Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
Problem Upload CSV File to WAPI -- File Upload Size of 0 bytes
Options
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2018 06:16 AM
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!
Labels: