hey everyone! i posted this question in the genera...
# suitescript
f
hey everyone! i posted this question in the general channel, but I will try here instead: I am having trouble with a custom online HTML form that i am working on for a custom record. I need to attach a few files to the custom record via file attachment fields on the online form. I am having trouble sending the file contents to the suitelet I have created which is responsible for taking the file contents, and uploading it into the file cabinet. Where I am struggling is really with the HTTP post request on my online form to take the contents from the file attachment fields and send the data to the suitelet. This is what i have so far in terms of the post request:
Copy code
var data = new FormData();
$.each( $( '.file' )[ 0 ].files, function( i, file ) {
  console.log( file );
  data.append( 'file-' + i, file );
} );
console.log( data );
$.ajax( {
  url: postURL,
  data: data,
  cache: false,
  contentType: false,
  processData: false,
  method: 'POST',
  type: 'POST', // For jQuery < 1.9
  success: function( data ) {
    alert( data );
  }
however, the body of the request in the suitelet is empty. any help is greatly appreciated!!
b
f
@battk this is definitely bringing me closer, thank you! however, I think I am constructing my post request incorrectly, i am not seeing anyway to get the contents from the file using the files property from the request on the suitelet. It tells me some useful information such as what is the file name, type, etc, but i am not particularly seeing how to pull the contents of the file to actual create the file in the file cabinet. here is what i see when i inspect request.files in my suitelet as an example:
Copy code
{
  "file-0": {
    "type": "file.File",
    "id": null,
    "name": "Custom_1000064.pdf",
    "description": null,
    "path": "Custom_1000064.pdf",
    "url": null,
    "folder": -1,
    "fileType": "PDF",
    "isText": false,
    "size": 59752,
    "encoding": null,
    "isInactive": false,
    "isOnline": false
  }
}
Thank you so so much for your help!
b
each of those objects is a file.File
f
oh wow, that is so interesting!!! I had no clue this existed... once again @battk, thank you, you truly saved my day!