# httpresponse Unsupported Media Type API upload file

**URL:** <https://community.hubspot.com/t/httpresponse-unsupported-media-type-api-upload-file/66766>\
**Category:** APIs & Integrations\
**Tags:** professional\
**Created:** [October 9, 2022, 12:56pm UTC](https://community.hubspot.com/t/httpresponse-unsupported-media-type-api-upload-file/66766 "2022-10-09T12:56:31Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arbi](https://avatars.discourse-cdn.com/v4/letter/a/41988e/32.png) [@Arbi](https://community.hubspot.com/u/Arbi)\
**Post date:** [October 9, 2022, 12:56pm UTC](https://community.hubspot.com/t/httpresponse-unsupported-media-type-api-upload-file/66766/1 "2022-10-09T12:56:31Z")

</div>

Hello,

i do use upload file API V3 in a Wix website, I start getting the error of unsupported Media Type, I don’t know, this is my code:

------------------------------------------------------------------------------

```lia-code-sample
export async function post_image () { 
 const manageUrl = 'https://api.hubapi.com/filemanager/api/v3/files/upload';

 const fileOptions = { 
access: 'PUBLIC_INDEXABLE', 
overwrite: false,
ttl:"P3M", 
duplicateValidationStrategy: 'NONE', 
duplicateValidationScope: 'ENTIRE_PORTAL', 
}; 
const fileParams = { 
options: JSON.stringify(fileOptions), 
folderPath: 'docs', 
}; 
let filename = "ninja.jpg"; 
const formdata = new FormData();
 formdata.append('file',fs.createReadStream("https://static.wixstatic.com/media/d8ba6f_c155297693b242a0bd84d149dec28a82~mv2.jpg"),filename); 
 Object.keys(fileParams).forEach((key) => formdata.append(key, fileParams[key])); 
let otp = { 
method: 'POST', 
headers:{
 'Authorization': `Bearer ${'My_Token'}`,
 },
body:JSON.stringify(formdata), 
}; 
console.log('opt', otp); 
return await fetch(manageUrl, otp) 
.then((httpResponse)=>{
 if(httpResponse.ok){ 
return httpResponse.json(); 
}else{ 
console.log('httpresponse', httpResponse.statusText); 
return Promise.reject("Fetch did not succeed");
 }
 });}
 ---------------------------------------------------------------------------------------------

```

**this is the console.log of opt:**

{ “method”: “POST”,

“headers”: { “Authorization”: “Bearer MY\_TOKEN” },

“body”: “{\”\_overheadLength\“:366,\”\_valueLength\“:143,\”\_valuesToMeasure\“:[{\”\_readableState\“:{\“objectMode\”:false,\“highWaterMark\”:65536,\“buffer\”:{\“head\”:null,\“tail\”:null,\“length\”:0},\“length\”:0,\“pipes\”:[],\“flowing\”:false,\“ended\”:false,\“endEmitted\”:false,\“reading\”:false,\“sync\”:true,\“needReadable\”:false,\“emittedReadable\”:false,\“readableListening\”:false,\“resumeScheduled\”:false,\“errorEmitted\”:false,\“emitClose\”:true,\“autoDestroy\”:false,\“destroyed\”:false,\“errored\”:null,\“closed\”:false,\“closeEmitted\”:false,\“defaultEncoding\”:\“utf8\”,\“awaitDrainWriters\”:null,\“multiAwaitDrain\”:false,\“readingMore\”:false,\“decoder\”:null,\“encoding\”:null},\”\_events\“:{},\”\_eventsCount\“:3,\“path\”:\”[[https://static.wixstatic.com/media/d8ba6f\_c155297693b242a0bd84d149dec28a82~mv2.jpg\\](https://static.wixstatic.com/media/d8ba6f%5C_c155297693b242a0bd84d149dec28a82~mv2.jpg%5C%5C)]([https://static.wixstatic.com/media/d8ba6f\_c155297693b242a0bd84d149dec28a82~mv2.jpg\](https://static.wixstatic.com/media/d8ba6f_c155297693b242a0bd84d149dec28a82~mv2.jpg%5C))

“,\“fd\”:null,\“flags\”:\“r\”,\“mode\”:438,\“end\”:null,\“autoClose\”:true,\“bytesRead\”:0,\“closed\”:false}],\“writable\”:false,\“readable\”:true,\“dataSize\”:0,\“maxDataSize\”:2097152,\“pauseStreams\”:true,\”\_released\“:false,\”\_streams\“:[\”----------------------------878248842902466855888581\\r\\nContent-Disposition: form-data; name=\\\“file\\\”; filename=\\\“ninja.jpg\\\”\\r\\nContent-Type: image/jpeg\\r\\n\\r\\n\“,{\“source\”:{\”\_readableState\“:{\“objectMode\”:false,\“highWaterMark\”:65536,\“buffer\”:{\“head\”:null,\“tail\”:null,\“length\”:0},\“length\”:0,\“pipes\”:[],\“flowing\”:false,\“ended\”:false,\“endEmitted\”:false,\“reading\”:false,\“sync\”:true,\“needReadable\”:false,\“emittedReadable\”:false,\“readableListening\”:false,\“resumeScheduled\”:false,\“errorEmitted\”:false,\“emitClose\”:true,\“autoDestroy\”:false,\“destroyed\”:false,\“errored\”:null,\“closed\”:false,\“closeEmitted\”:false,\“defaultEncoding\”:\“utf8\”,\“awaitDrainWriters\”:null,\“multiAwaitDrain\”:false,\“readingMore\”:false,\“decoder\”:null,\“encoding\”:null},\”\_events\“:{},\”\_eventsCount\“:3,\“path\”:\” [https://static.wixstatic.com/media/d8ba6f\_c155297693b242a0bd84d149dec28a82~mv2.jpg\\“,\\“fd\\”:null,\\“flags\\”:\\“r\\”,\\“mode\\”:438,\\“end\\”:null,\\“autoClose\\”:true,\\“bytesRead\\”:0,\\“closed\\”:false},\\“dataSize\\”:0,\\“maxDataSize\\”:null,\\“pauseStream\\”:true,\\”\_maxDataSizeExceeded\\“:false,\\”\_released\\“:false,\\”\_bufferedEvents\\“:\[{\\“0\\”:\\“pause\\”}],\\”\_events\\“:{},\\”\_eventsCount\\“:1},null,\\”\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-878248842902466855888581\\\r\\\nContent-Disposition:](https://static.wixstatic.com/media/d8ba6f%5C_c155297693b242a0bd84d149dec28a82~mv2.jpg%5C%5C%22,%5C%5C%22fd%5C%5C%22:null,%5C%5C%22flags%5C%5C%22:%5C%5C%22r%5C%5C%22,%5C%5C%22mode%5C%5C%22:438,%5C%5C%22end%5C%5C%22:null,%5C%5C%22autoClose%5C%5C%22:true,%5C%5C%22bytesRead%5C%5C%22:0,%5C%5C%22closed%5C%5C%22:false%7D,%5C%5C%22dataSize%5C%5C%22:0,%5C%5C%22maxDataSize%5C%5C%22:null,%5C%5C%22pauseStream%5C%5C%22:true,%5C%5C%22%5C_maxDataSizeExceeded%5C%5C%22:false,%5C%5C%22%5C_released%5C%5C%22:false,%5C%5C%22%5C_bufferedEvents%5C%5C%22:%5C%5B%7B%5C%5C%220%5C%5C%22:%5C%5C%22pause%5C%5C%22%7D%5D,%5C%5C%22%5C_events%5C%5C%22:%7B%7D,%5C%5C%22%5C_eventsCount%5C%5C%22:1%7D,null,%5C%5C%22%5C-%5C-%5C-%5C-%5C-%5C-%5C-%5C-%5C-%5C-%5C-%5C-%5C-%5C-%5C-%5C-%5C-%5C-%5C-%5C-%5C-%5C-%5C-%5C-%5C-%5C-%5C-%5C-878248842902466855888581%5C%5C%5Cr%5C%5C%5CnContent-Disposition:) form-data; name=\\\“options\\\”\\r\\n\\r\\n\“,\”{\\\“access\\\”:\\\“PUBLIC\_INDEXABLE\\\”,\\\“overwrite\\\”:false,\\\“ttl\\\”:\\\“P3M\\\”,\\\“duplicateValidationStrategy\\\”:\\\“NONE\\\”,\\\“duplicateValidationScope\\\”:\\\“ENTIRE\_PORTAL\\\”}\“,null,\”----------------------------878248842902466855888581\\r\\nContent-Disposition: form-data; name=\\\“folderPath\\\”\\r\\n\\r\\n\“,\“docs\”,null],\”\_currentStream\“:null,\”\_insideLoop\“:false,\”\_pendingNext\“:false,\”\_boundary\“:\”--------------------------878248842902466855888581\“}” }

**---------------------------------------------------------------------------------------------------**

I don’t mention the Content-Type because I’m using FormData.

Can anyone see the issue here?

Thanks!

---

<div class="post-metadata">

**Author:** ![Teun](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/teun/32/28739_2.png) [@Teun](https://community.hubspot.com/u/Teun)\
**Post date:** [October 10, 2022, 6:54am UTC](https://community.hubspot.com/t/httpresponse-unsupported-media-type-api-upload-file/66766/2 "2022-10-10T06:54:08Z")

</div>

Hi @Arbi ,

When I try to visit the [URL](https://static.wixstatic.com/media/d8ba6f_c155297693b242a0bd84d149dec28a82~mv2.jpg/) in the response, I get a forbidden message. This could be the cause of your issue.

---

<div class="post-metadata">

**Author:** ![Arbi](https://avatars.discourse-cdn.com/v4/letter/a/41988e/32.png) [@Arbi](https://community.hubspot.com/u/Arbi)\
**Post date:** [October 10, 2022, 8:54am UTC](https://community.hubspot.com/t/httpresponse-unsupported-media-type-api-upload-file/66766/3 "2022-10-10T08:54:28Z")

</div>

Hey @Teun,

Thanks for your reply,

Yep when i click on the URL displayed in the console.log() it says that is “Forbidden” because it add a slash at the end of the static URL. This is weird because when you look at the formData the file URL doesn’t have “/” at the end.

---

<div class="post-metadata">

**Author:** ![Teun](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/teun/32/28739_2.png) [@Teun](https://community.hubspot.com/u/Teun)\
**Post date:** [October 10, 2022, 8:59am UTC](https://community.hubspot.com/t/httpresponse-unsupported-media-type-api-upload-file/66766/4 "2022-10-10T08:59:30Z")

</div>

Hi @Arbi ,

Does your code work if you try this [image](https://picsum.photos/200/300) instead?

---

<div class="post-metadata">

**Author:** ![Arbi](https://avatars.discourse-cdn.com/v4/letter/a/41988e/32.png) [@Arbi](https://community.hubspot.com/u/Arbi)\
**Post date:** [October 10, 2022, 9:20am UTC](https://community.hubspot.com/t/httpresponse-unsupported-media-type-api-upload-file/66766/5 "2022-10-10T09:20:13Z")

</div>

Hi @Teun,

I’ve tried with this image but it’s the same Error, “Unsupported Media Type”

---

<div class="post-metadata">

**Author:** ![Teun](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/teun/32/28739_2.png) [@Teun](https://community.hubspot.com/u/Teun)\
**Post date:** [October 10, 2022, 11:13am UTC](https://community.hubspot.com/t/httpresponse-unsupported-media-type-api-upload-file/66766/6 "2022-10-10T11:13:52Z")

</div>

Hi @Arbi ,

I found the solution. You are using the wrong endpoint. This endpoint expects a file to be uploaded that is currently available in your system, however, you want to download an image from an URL and upload that image. If that’s the case, you need this endpoint: /files/v3/files/import-from-url/async

---

<div class="post-metadata">

**Author:** ![Arbi](https://avatars.discourse-cdn.com/v4/letter/a/41988e/32.png) [@Arbi](https://community.hubspot.com/u/Arbi)\
**Post date:** [October 10, 2022, 6:25pm UTC](https://community.hubspot.com/t/httpresponse-unsupported-media-type-api-upload-file/66766/7 "2022-10-10T18:25:04Z")

</div>

Hi @Teun,

I’ve tried with the new endpoint and still getting the same error. I’ve noticed a new error “Error: Fetch did not succeed at c ([https://static.parastorage.com/services/wix-code-viewer-app/1.1479.539/app.js:3:10527](https://static.parastorage.com/services/wix-code-viewer-app/1.1479.539/app.js:3:10527))”, which I don’t know it means. I think I can’t access Wix static files, that’s why I’m getting an “Unsupported Media Type” error.
