files/v3/files error

Hello,

I am trying to create a file using the new /files/v3/files API. When I am passing in the formData to the API I am getting the following reponse:

{

status: ‘error’,

message: ‘Could not determine name from file’,

correlationId: ‘473023e1-6489-450e-81ed-feacdc2fbfb7’,

category: ‘BAD_REQUEST’

}

I am creating the file and then planning on attaching the file to note to append to deals.

Could you give me some insight on this?

Thanks!

@CRedmon ,

Mind adding the json body as well as the full request uri that you are submitting to? (minus a hapikey)

@tominal maybe able to assist when there are more details :grinning_face:

Hi @dennisedson ,
I am submitting form data to the api because it is a “multipart/form-data” so here is the best I can do.
FormData object:

{

file: <buffer>,
fileName: <string>,
options:

{

    access: "PUBLIC\_INDEXABLE",

    ttl: "P3M",

   overwrite: false,

  duplicateValidationStrategy: "NONE",

  duplicateValidationScope: "ENTIRE\_PORTAL",

}

}

From Axios request:
url: ‘/files/v3/files’,

method: 'post',

data: FormData {

  \_overheadLength: 425,

  \_valueLength: 4297,

  \_valuesToMeasure: \[],

  writable: false,

  readable: true,

  dataSize: 0,

  maxDataSize: 2097152,

  pauseStreams: true,

  \_released: true,

  \_streams: \[],

  \_currentStream: **null**,

  \_insideLoop: false,

  \_pendingNext: false,

  \_boundary: '\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-264236909180776376341869',

  \_events: \[Object: null prototype],

  \_eventsCount: 1

},

headers: {

  Accept: 'application/json, text/plain, \*/\*',

  'Content-Type': 'multipart/form-data; boundary=\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-264236909180776376341869',

  Authorization: 'Bearer \<valid oauth token>',

  'User-Agent': 'axios/0.21.1'

},

baseURL: 'https://api.hubapi.com/',

Throwing @tjoyce into this as well :grinning_face:

@CRedmon - Does my answer on this post help you out?

https://community.hubspot.com/t5/APIs-Integrations/Can-t-get-file-upload-via-file-API-to-work-please-help/m-p/426872#M42413

@tjoyce Hi! I am not a php developer but after looking at your post I did some digging and found what I was missing. In my form body I was missing another parameter on the file property to pass the filename (hence my error).

For all the nodejs devs out there:

const bodyFormData = new FormData();
 bodyFormData.append("file", file.content, { filename: file.filename });
 bodyFormData.append("folderPath", folderPath);
 bodyFormData.append(
 "options",
 JSON.stringify({
 access: "PRIVATE",
 overwrite: true,
 duplicateValidationStrategy: "NONE",
 duplicateValidationScope: "EXACT_FOLDER",
 })
 );

 return _api
 .post("/files/v3/files", bodyFormData, {
 headers: {
 Authorization: `Bearer ${token}`,
 ...bodyFormData.getHeaders(),
 },
 })
 .then(({ data }) => data)
 .catch(e => {
 console.log(e);
 throw new Error(
 `Failed getting creating file ${e.response?.status} - ${e.response?.statusText} - ${e.response?.data?.message}`
 );
 });