Hey all! I’m uploading pdf’s through a suitelet an...
# suitescript
j
Hey all! I’m uploading pdf’s through a suitelet and I’ve got everything working, except the files are coming through blank/empty. I know I should be putting something in as the contents, but how do I handle that dynamically?
var fileObj = file.create({
name: fileUpload,
fileType: file.Type.PDF
});
j
I haven't done this in a while but I think you have to set the
content
member to the ... well ... content, and set the encoding to UTF-8
b
if you are using a file field on a form, netsuite should create the file object for you
j
Hey guys thanks. I have tried .save() directly on the file returned in the request.parameters but that isnt working. How would I set the contents from a pdf? I believe that is where the problem lies.
b
you need to set the folder first
j
yeah I have the folder set and the encoding set. Its saving in the folder as a pdf. Its just blank
b
whats the code
keep in mind that i meant to set the folder of the file from the suitelet before saving it
j
var fileUpload = context.request.parameters.custpage_file;
var fileObj = file.create({
name: fileUpload,
fileType: file.Type.PDF
});
fileObj.folder = 691338;
fileObj.encoding = file.Encoding.UTF8;
var fileId = fileObj.save();
b
Copy code
var fileUpload = context.request.files.custpage_file;
fileUpload.folder = "691338";
var fileId = fileUpload.save();
use ServerRequest.files to get the file object
j
Getting this without running the file.create() on the pdf: Cannot find function save in object sample.pdf.
b
what code?
j
var fileUpload = context.request.files.custpage_file;
fileUpload.folder = "691338";
var fileId = fileUpload.save();
b
how are you creating the field
j
Just in a html template
<input type="file" name="custpage_file">
b
not sure how you can get a native html field working
if you want netsuite to handle the file creation for you, you need to use a pageObject created by N/ui/serverWidget
j
gotcha, so just create the form with serverWidget.createForm()?
b
yes
j
Awesome. thanks for all the help. appreciate it