files/v3/files error

SOLVE
CRedmon
Participant

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!

 

0 Upvotes
1 Accepted solution

Accepted Solutions
CRedmon
Solution
Participant

@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}`
      );
    });

 

 

View solution in original post

5 Replies 5
dennisedson
Community Manager

@CRedmon ,

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

@RBThomas maybe able to assist when there are more details 😀

Thanks,

Dennis




Check out our Community Developer Blog
where we feature our Community driven developer podcast and how to content
0 Upvotes
CRedmon
Participant

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/',

dennisedson
Community Manager

Throwing @tjoyce into this as well 😀

Thanks,

Dennis




Check out our Community Developer Blog
where we feature our Community driven developer podcast and how to content
tjoyce
Recognized Expert | Platinum Partner
CRedmon
Solution
Participant

@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}`
      );
    });

 

 

View solution in original post