Reply

Problem Upload CSV File to WAPI -- File Upload Size of 0 bytes

New Member
Posts: 1
7753     0

Hello,

 

I am working on writing a JavaScript program to use the REST API to upload a CSV to make changes to the grid. I have been able to succesfully do this with REST calls on the command line and it works well. However, when I do this in JavaScript code -- making the same REST calls -- the file upload size returns 0, even though the file is present and of a non-zero-sized file.

 

I followed the script laid out here.

 

Here is the script that I've written:

 

try {
    // Contact InfoBlox to initiate the upload and get a token for the upload.
    const initateUpload = await request.post({
      headers: { 'content-type': 'application/json' },
      strictSSL: false,
      url: initializeUploadUrl,
      auth: {
        user: id,
        pass: pass,
      },
    });
    const uploadToken = JSON.parse(initateUpload).token;
    const uploadUrl = JSON.parse(initateUpload).url;
    console.log(`Uploading  to ${uploadUrl}`);
    console.log(`With token ${uploadToken}`);

    // This request does not return a JSON response
    await request.post({
      headers: { 'content-type': 'multipart/form-data' },
      strictSSL: false,
      url: uploadUrl,
      auth: {
        user: id,
        pass: pass,
      },
      form: {
        file: '@tmp.csv', // `@${csvFpath}`,
      },
    });

    const fileUpload = await request.post({
      headers: { 'content-type': 'application/json' },
      strictSSL: false,
      url: importUrl,
      auth: {
        user: id,
        pass: pass,
      },
      json: { action: 'START', on_error: 'CONTINUE', update_method: 'OVERRIDE', token: uploadToken },
    });
    console.log(fileUpload); // THIS is where file size is 0.

  } catch (error) {
    parseErrorResponse(error);
    // throw error;
  }

Any insight into what's happening?

 

Thank you!

Showing results for 
Search instead for 
Did you mean: 

Recommended for You