# Error 415 when uploading files

**URL:** <https://community.hubspot.com/t/error-415-when-uploading-files/77783>\
**Category:** APIs & Integrations\
**Tags:** developer-tools\
**Created:** [March 22, 2023, 9:44pm UTC](https://community.hubspot.com/t/error-415-when-uploading-files/77783 "2023-03-22T21:44:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![TaylorAran](https://avatars.discourse-cdn.com/v4/letter/t/e9a140/32.png) [@TaylorAran](https://community.hubspot.com/u/TaylorAran)\
**Post date:** [March 22, 2023, 9:44pm UTC](https://community.hubspot.com/t/error-415-when-uploading-files/77783/1 "2023-03-22T21:44:51Z")

</div>

Hello,

When trying to upload a PDF file via fetch(), I keep getting a 415 error. The PDF file is saved in the same directory as the js file.

Please see my function. I have tried changing the “Content-Type” in headers to several different options, and all spit back 400 and 415 errors.

When I use request.post() instead of fetch(), I can upload the file. But I want to use fetch(). So what’s the issue?

Any help you can provide would be much appreciated.

```lia-code-sample
async function uploadFile(filePath, extension, timestamp) {

 const url = "https://api.hubapi.com/files/v3/files";
 var filename = `${filePath}.${extension}`;

 var fileOptions = {
 access: 'PRIVATE',
 overwrite: false,
 duplicateValidationStrategy: 'NONE',
 duplicateValidationScope: 'ENTIRE_PORTAL'
 };

 var formData = {
 file: fs.createReadStream(filename),
 fileName: `${filename} (${timestamp}).${extension}`,
 options: JSON.stringify(fileOptions),
 folderPath: 'Quotations'
 };

 try {
 const response = await fetch(url, { 
 "method": "POST",
 "formData": formData,
 "headers": {
 'Authorization': `Bearer ${process.env.ACCESS_TOKEN}`,
 "Content-Type": "application/pdf"
 }
 });

 if(!response.ok) {
 throw new Error(`HTTP Error: ${response.status}`);
 }

 const data = await response.json();
 return data;

 } catch(error) {
 console.log(`Error: ${error}`);
 }

}

const fileId = uploadFile("Quotation", "pdf", getCurrentTimestamp());
fileId.then((data) => console.log(data));

```

---

<div class="post-metadata">

**Author:** ![JairoPy](https://avatars.discourse-cdn.com/v4/letter/j/9f8e36/32.png) [@JairoPy](https://community.hubspot.com/u/JairoPy)\
**Post date:** [March 22, 2023, 11:55pm UTC](https://community.hubspot.com/t/error-415-when-uploading-files/77783/2 "2023-03-22T23:55:59Z")

</div>

Have you tried setting the content type as multipart/form-data?

---

<div class="post-metadata">

**Author:** ![TaylorAran](https://avatars.discourse-cdn.com/v4/letter/t/e9a140/32.png) [@TaylorAran](https://community.hubspot.com/u/TaylorAran)\
**Post date:** [March 23, 2023, 7:46am UTC](https://community.hubspot.com/t/error-415-when-uploading-files/77783/3 "2023-03-23T07:46:09Z")

</div>

Hi @JairoPy,

Thanks for your reply.

Yes, I have tried that, but the reponse is always: “Error: Error: HTTP Error: 400”.

I have also tried “application/json”, which returns: “Error: Error: HTTP Error: 415”.

Commenting out the “Content-Type” line returns: “Error: Error: HTTP Error: 400”.

For the sake of trying everything, I also tried “text/plain”, but that returns “Error: Error: HTTP Error: 415”.

---

<div class="post-metadata">

**Author:** ![JairoPy](https://avatars.discourse-cdn.com/v4/letter/j/9f8e36/32.png) [@JairoPy](https://community.hubspot.com/u/JairoPy)\
**Post date:** [March 23, 2023, 12:54pm UTC](https://community.hubspot.com/t/error-415-when-uploading-files/77783/4 "2023-03-23T12:54:58Z")

</div>

Well, I guess the issue is that the fetch api as it is client side is subject to cross origin problems, as this endpoint requests authorization you just be able to reach it from your backend, that’s why you’re request works with the request node package but no with fetch api.

If you want to fetch any info from this api to the frontend, you could create an internal api to gather the data from hubspot and expose it to your client side.
