I need my Restlet to accept a file - and then atta...
# suitescript
m
I need my Restlet to accept a file - and then attach the file to a record. Do we use the n/file module for this?
b
there arent really good options for restlet file input
best i know of is to add the file contents to a key on the restlet input (base 64 encode it if its binary)
then use N/file to save the file in the file cabinet somwhere
then use record.attach to attach the file
keep in mind the 10 mb input limit
m
Thanks for the guidelines. Would that be 10mb per file?
b
request body total
m
just going back your suggestion from a few days back - assuming attachment above is an input file that is base64 encoded - is that how you would then process the file?
this code saves my image file in the file cabinet but just wanted to check if this is what you meant or if there should be something else I take into consideration
b
the file content should base64 encoded when you post to the restlet
you would not want to decode it before saving
m
So the file should already be base64 when passed to the restlet. This mean I dont need to do anything further in my restlet?
b
yes
you will have trouble passing an unencoded value as json
m
finally got shopify to send data to the restlet and the file coming is base64 encoded - i am not sure what to do with this data now. I was just expecting a file name so my code handled it in this manner:
Untitled
i had the attachment in an array when I was testing using postman to send some file names
b
either make up names for your image
or make shopify send the name too