"use strict";(self.webpackChunknewoaks_help=self.webpackChunknewoaks_help||[]).push([[8590],{5933:(e,n,s)=>{s.r(n),s.d(n,{assets:()=>o,contentTitle:()=>l,default:()=>h,frontMatter:()=>i,metadata:()=>t,toc:()=>d});const t=JSON.parse('{"id":"api/upload-file","title":"Upload a file","description":"- Step 1 : Retrieve the upload URL.","source":"@site/developer/api/102.upload-file.md","sourceDirName":"api","slug":"/api/upload-file","permalink":"/guides/developer/api/upload-file","draft":false,"unlisted":false,"tags":[],"version":"current","sidebarPosition":3,"frontMatter":{"sidebar_position":3},"sidebar":"sidebar","previous":{"title":"Regions","permalink":"/guides/developer/api/region"},"next":{"title":"Get AI Model List","permalink":"/guides/developer/api/get-ai-model-list"}}');var r=s(4848),a=s(8453);const i={sidebar_position:3},l="Upload a file",o={},d=[{value:"To retrieve an upload URL",id:"to-retrieve-an-upload-url",level:2},{value:"Endpoint",id:"endpoint",level:3},{value:"Request Headers",id:"request-headers",level:3},{value:"Request Body",id:"request-body",level:3},{value:"Example Request",id:"example-request",level:3},{value:"JavaScript (Fetch API)",id:"javascript-fetch-api",level:5},{value:"Python (Requests Library)",id:"python-requests-library",level:5},{value:"cURL",id:"curl",level:5},{value:"HTTP Request",id:"http-request",level:5},{value:"Response",id:"response",level:3},{value:"Error Handling",id:"error-handling",level:3},{value:"Mark the upload as successful",id:"mark-the-upload-as-successful",level:2},{value:"Endpoint",id:"endpoint-1",level:3},{value:"Request Headers",id:"request-headers-1",level:3},{value:"Request Body",id:"request-body-1",level:3},{value:"Example Request",id:"example-request-1",level:3},{value:"JavaScript (Fetch API)",id:"javascript-fetch-api-1",level:5},{value:"Python (Requests Library)",id:"python-requests-library-1",level:5},{value:"cURL",id:"curl-1",level:5},{value:"HTTP Request",id:"http-request-1",level:5},{value:"Response",id:"response-1",level:3},{value:"Error Handling",id:"error-handling-1",level:3}];function c(e){const n={code:"code",h1:"h1",h2:"h2",h3:"h3",h5:"h5",header:"header",li:"li",p:"p",pre:"pre",ul:"ul",...(0,a.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(n.header,{children:(0,r.jsx)(n.h1,{id:"upload-a-file",children:"Upload a file"})}),"\n",(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsx)(n.li,{children:"Step 1 : Retrieve the upload URL."}),"\n",(0,r.jsx)(n.li,{children:"Step 2 : Upload the file using the URL via the PUT method."}),"\n",(0,r.jsx)(n.li,{children:"Step 3 : Mark the file upload as successful."}),"\n"]}),"\n",(0,r.jsx)(n.h2,{id:"to-retrieve-an-upload-url",children:"To retrieve an upload URL"}),"\n",(0,r.jsx)(n.p,{children:"This API generates a pre-signed URL for file uploads, allowing files to be uploaded directly to the specified location. Please note that the URL is time-sensitive and will expire after 5 minutes."}),"\n",(0,r.jsx)(n.h3,{id:"endpoint",children:"Endpoint"}),"\n",(0,r.jsx)(n.p,{children:(0,r.jsx)(n.code,{children:"POST https://usapi.hottask.com/chat/User/GetPreUploadUrl"})}),"\n",(0,r.jsx)(n.h3,{id:"request-headers",children:"Request Headers"}),"\n",(0,r.jsx)(n.p,{children:"The API request must include the following headers:"}),"\n",(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"Authorization: <Your-Secret-Key>"})," - The secret key for authenticating the API request."]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"Content-Type: application/json"})," - The content type of the request payload."]}),"\n"]}),"\n",(0,r.jsx)(n.h3,{id:"request-body",children:"Request Body"}),"\n",(0,r.jsx)(n.p,{children:"The request body should contain the following parameters:"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-JSON",children:'{\n  // fileName(string, required): The filename. EG: companyinfo.txt\n  "fileName":"companyinfo.txt" \n}\n'})}),"\n",(0,r.jsx)(n.h3,{id:"example-request",children:"Example Request"}),"\n",(0,r.jsx)(n.h5,{id:"javascript-fetch-api",children:"JavaScript (Fetch API)"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-javascript",children:"const res = await fetch('https://usapi.hottask.com/chat/User/GetPreUploadUrl', {\n  method: 'POST',\n  headers: {\n    'Authorization': `<Your-Secret-Key>`,\n    'Content-Type': 'application/json',\n  },\n  body: JSON.stringify({\n    fileName: '<Your filename>',\n  }),\n});\n\nconst data = await res.json();\nconsole.log(data);\n"})}),"\n",(0,r.jsx)(n.h5,{id:"python-requests-library",children:"Python (Requests Library)"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-python",children:"import requests\nimport json\n\nurl = 'https://usapi.hottask.com/chat/User/GetPreUploadUrl'\nheaders = {\n    'Authorization': '<Your-Secret-Key>',\n    'Content-Type': 'application/json'\n}\ndata = {\n    'fileName': '<Your filename>'\n}\n\nresponse = requests.post(url, headers=headers, data=json.dumps(data))\ndata = response.json()\n\nprint(data) \n"})}),"\n",(0,r.jsx)(n.h5,{id:"curl",children:"cURL"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-bash",children:"curl https://usapi.hottask.com/chat/User/GetPreUploadUrl \\\n  -H 'Content-Type: application/json' \\\n  -H 'Authorization: <Your-Secret-Key>' \\\n  -d '{\"fileName\": \"your filename\"}'\n"})}),"\n",(0,r.jsx)(n.h5,{id:"http-request",children:"HTTP Request"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{children:'POST /chat/User/GetPreUploadUrl HTTP/1.1\nHost: usapi.hottask.com\nAuthorization: <Your-Secret-Key>\nContent-Type: application/json\n\n{\n  "fileName": "<Your filename>"\n}\n'})}),"\n",(0,r.jsx)(n.h3,{id:"response",children:"Response"}),"\n",(0,r.jsx)(n.p,{children:"The API response will be a JSON object with the following structure:"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-json",children:'{\n  "Data": {\n    "FileStoreId":"34317",\n    "PreUploadUrl":"https://xxx.s3.us-west-1.amazonaws.com/xxx/3706/627855d5-ba01-4732-9dfd-b08a72744c77.txt?X-Amz-Expires=600\\u0026X-Amz-Algorithm=AWS4-HMAC-SHA256\\u0026X-Amz-Credential=AKIA5TS7CBKE4ZSWBI46%2F20250121%2Fus-west-1%2Fs3%2Faws4_request\\u0026X-Amz-Date=20250121T030214Z\\u0026X-Amz-SignedHeaders=host\\u0026X-Amz-Signature=a237335d9b2e6fad1c648f753d393906647db5528eaaecf5e55dd114a22653db",\n  },\n  "Version": "1.0.0",\n  "Success": true,\n  "Code": 200,\n  "Message":""\n}\n'})}),"\n",(0,r.jsx)(n.p,{children:"\u200b"}),"\n",(0,r.jsx)(n.h3,{id:"error-handling",children:"Error Handling"}),"\n",(0,r.jsxs)(n.p,{children:["If it's an HTTP network error, you should check the ",(0,r.jsx)(n.code,{children:"HTTP status code"}),". If it's a business exception, you need to examine the ",(0,r.jsx)(n.code,{children:"Code"})," and ",(0,r.jsx)(n.code,{children:"Message"})," fields, which will provide the error details."]}),"\n",(0,r.jsx)(n.p,{children:"That\u2019s it! You should now be able to create a chatbot using the create API."}),"\n",(0,r.jsx)(n.h2,{id:"mark-the-upload-as-successful",children:"Mark the upload as successful"}),"\n",(0,r.jsx)(n.p,{children:"This API allows the user to mark the file as successfully uploaded."}),"\n",(0,r.jsx)(n.h3,{id:"endpoint-1",children:"Endpoint"}),"\n",(0,r.jsx)(n.p,{children:(0,r.jsx)(n.code,{children:"POST https://usapi.hottask.com/chat/User/ReportUploadSuccess"})}),"\n",(0,r.jsx)(n.h3,{id:"request-headers-1",children:"Request Headers"}),"\n",(0,r.jsx)(n.p,{children:"The API request must include the following headers:"}),"\n",(0,r.jsxs)(n.ul,{children:["\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"Authorization: <Your-Secret-Key>"})," - The secret key for authenticating the API request."]}),"\n",(0,r.jsxs)(n.li,{children:[(0,r.jsx)(n.code,{children:"Content-Type: application/json"})," - The content type of the request payload."]}),"\n"]}),"\n",(0,r.jsx)(n.h3,{id:"request-body-1",children:"Request Body"}),"\n",(0,r.jsx)(n.p,{children:"The request body should contain the following parameters:"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-JSON",children:'{\n  // fileStoreID(string, required): The file id.\n  "fileStoreID":"123"\n}\n'})}),"\n",(0,r.jsx)(n.h3,{id:"example-request-1",children:"Example Request"}),"\n",(0,r.jsx)(n.h5,{id:"javascript-fetch-api-1",children:"JavaScript (Fetch API)"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-javascript",children:"const res = await fetch('https://usapi.hottask.com/chat/User/ReportUploadSuccess', {\n  method: 'POST',\n  headers: {\n    'Authorization': `<Your-Secret-Key>`,\n    'Content-Type': 'application/json',\n  },\n  body: JSON.stringify({\n    fileStoreID: '123'\n  }),\n});\n\nconst data = await res.json();\nconsole.log(data);\n"})}),"\n",(0,r.jsx)(n.h5,{id:"python-requests-library-1",children:"Python (Requests Library)"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-python",children:"import requests\nimport json\n\nurl = 'https://usapi.hottask.com/chat/User/ReportUploadSuccess'\nheaders = {\n    'Authorization': '<Your-Secret-Key>',\n    'Content-Type': 'application/json'\n}\ndata = {\n    'fileStoreID': '123'\n}\n\nresponse = requests.post(url, headers=headers, data=json.dumps(data))\ndata = response.json()\n\nprint(data) \n"})}),"\n",(0,r.jsx)(n.h5,{id:"curl-1",children:"cURL"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-bash",children:"curl https://usapi.hottask.com/chat/User/ReportUploadSuccess \\\n  -H 'Content-Type: application/json' \\\n  -H 'Authorization: <Your-Secret-Key>' \\\n  -d '{\"fileStoreID\": \"123\"}'\n"})}),"\n",(0,r.jsx)(n.h5,{id:"http-request-1",children:"HTTP Request"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{children:'POST /chat/User/ReportUploadSuccess HTTP/1.1\nHost: usapi.hottask.com\nAuthorization: <Your-Secret-Key>\nContent-Type: application/json\n\n{\n  "fileStoreID": "123"\n}\n'})}),"\n",(0,r.jsx)(n.h3,{id:"response-1",children:"Response"}),"\n",(0,r.jsx)(n.p,{children:"The API response will be a JSON object with the following structure:"}),"\n",(0,r.jsx)(n.pre,{children:(0,r.jsx)(n.code,{className:"language-json",children:'{\n  "Data": true, \n  "Version": "1.0.0",\n  "Success": true,\n  "Code": 200,\n  "Message":""\n}\n'})}),"\n",(0,r.jsx)(n.p,{children:"\u200b"}),"\n",(0,r.jsx)(n.h3,{id:"error-handling-1",children:"Error Handling"}),"\n",(0,r.jsxs)(n.p,{children:["If it's an HTTP network error, you should check the ",(0,r.jsx)(n.code,{children:"HTTP status code"}),". If it's a business exception, you need to examine the ",(0,r.jsx)(n.code,{children:"Code"})," and ",(0,r.jsx)(n.code,{children:"Message"})," fields, which will provide the error details."]}),"\n",(0,r.jsx)(n.p,{children:"That\u2019s it! You should now be able to upload a file using these two APIs."})]})}function h(e={}){const{wrapper:n}={...(0,a.R)(),...e.components};return n?(0,r.jsx)(n,{...e,children:(0,r.jsx)(c,{...e})}):c(e)}},8453:(e,n,s)=>{s.d(n,{R:()=>i,x:()=>l});var t=s(6540);const r={},a=t.createContext(r);function i(e){const n=t.useContext(a);return t.useMemo((function(){return"function"==typeof e?e(n):{...n,...e}}),[n,e])}function l(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:i(e.components),t.createElement(a.Provider,{value:n},e.children)}}}]);