has anyone done a sharepoint integration to upload...
# suitescript
n
has anyone done a sharepoint integration to upload files from NetSuite to Sharepoint? I got the file to upload but for some reason it's like corrupted or something. Keep getting a 400 error back.
Copy code
var fileContent = fileObj.getContents();

var uploadResponse = https.put({
                url: `<https://graph.microsoft.com/v1.0/drives/${driveId}/root:/SharedDoc/test.png:/content>`,
                body: fileContent,
                headers: {
                    'Authorization': 'Bearer ' + token,
                    'Accept': 'application/json;odata=verbose',
                    'Content-Type': 'image/png' || 'application/octet-stream'
                }
            });
z
Are you sure if it is even possible to upload file SharePoint using that way? Only https.post with Bearer Did you try the same thing with PostMan?
n
yes I had it as PUT sorry fixed in post
It uploads the file but seems corrupted. Do you have to change the encoding or anything?
b
suitescript doesnt actually handle binary content very well
N/https only makes requests using plain text
and N/file represents binary as base64, essentially binary represented in plaintext
sharepoint doesnt know that you are trying to upload a file represented in base 64, thus assuming that the base64 string is the actual contents of the file
n
@battk So should I be encoding or changing the contents from n/file to work with sharepoint? If so, what format is recommended?
b
you have no choice, N/https only works with plaintext
unless sharepoint's api supports specifying an encoding, you wont be able to use suitescript to upload a file
common alternatives is the use of some sort of middleware to do what suitescript cannot
1
n
okay got ya thanks