question

DovLevyDNATECHComputerSolutions-8685 avatar image
0 Votes"
DovLevyDNATECHComputerSolutions-8685 asked DovLevy-1580 answered

Graph API small file upload success but docx won't open in browser, error in desktop app

Hi, I am using Zoho Deluge to download a file from Box using Box API then upload to Sharepoint using Graph API.

The file uploads but gets corrupted. Works fine in Postman using Binary body option.

In word online I get:

190336-image.png


And in desktop Word:

190355-image.png

This is the script I've written. The Graph response looks normal:

// Upload file to Sharepoint
graph_header = Map();
graph_header.put("Authorization","Bearer " + graph_access_token);
graph_header.put("Content-Type","octet-stream");
graph_body = Map();
graph_body.put("file",new_box_file);
graph_upload_file = invokeurl
[
url :"https://graph.microsoft.com/v1.0/drives/b!cBfsvaQVPlqf5An1C82RbwVjjG22-Qo9S4bs-PPMe/items/root:/" + file_name + ":/content"
type :PUT
parameters:graph_body
headers:graph_header
];
info graph_upload_file;

Any help would be appreciated. Thanks!

microsoft-graph-files
image.png (31.1 KiB)
image.png (13.5 KiB)
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello @DovLevyDNATECHComputerSolutions-8685, what is the size of your file?

0 Votes 0 ·

The @ZehuiYaoMSFT-7151 the test file is 13.7kb. Thanks

0 Votes 0 ·
ZehuiYaoMSFT-7151 avatar image
0 Votes"
ZehuiYaoMSFT-7151 answered ZehuiYaoMSFT-7151 commented

Hello @DovLevyDNATECHComputerSolutions-8685, I tested in postman and please try to add the property content-length in code, hope it helps.

190826-image.png




If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



image.png (210.9 KiB)
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you @ZehuiYaoMSFT-7151 but I'm trying to add the files size that I've pulled in from Box

// Get new Box file info
box_info_header = Map();
box_info_header.put("Authorization","Bearer " + box_access_token);
box_info_header.put("Content-Type","application/json");
new_box_file_info = invokeurl
[
url :"https://api.box.com/2.0/files/" + file_id
type :GET
headers:box_info_header
];
// info "File info:- " + new_box_file_info;
box_file_size = new_box_file_info.get("size");
box_file_size_range = "bytes 0-" + box_file_size + "/" + box_file_size;


In graph I add the header parameter:
graph_header.put("Content-Range",box_file_size_range);

Or

graph_header.put("Content-Length",box_file_size);

Both give the same original error.

By the way, to clarify I am using small file upload https://docs.microsoft.com/en-us/graph/api/driveitem-put-content?view=graph-rest-1.0&tabs=http not resumable file upload.

0 Votes 0 ·
ZehuiYaoMSFT-7151 avatar image ZehuiYaoMSFT-7151 DovLevyDNATECHComputerSolutions-8685 ·

I tested locally and everything works fine, still can't reproduce your issue, I need to discuss with my colleague and get back to you later.
191270-image.png
191278-image.png


0 Votes 0 ·
image.png (104.4 KiB)
image.png (212.2 KiB)
ZehuiYaoMSFT-7151 avatar image ZehuiYaoMSFT-7151 DovLevyDNATECHComputerSolutions-8685 ·

Hello @DovLevyDNATECHComputerSolutions-8685, we haven't found a workaround yet, I recommend opening a support ticket.

0 Votes 0 ·
DovLevy-1580 avatar image
0 Votes"
DovLevy-1580 answered

OP here on a different account.

Been working on this without success and think I have a breakthrough.

Summary of issues:

MS Graph small file upload works but file is corrupted.

MS Graph resumable large file upload errors out (no code) if I add Content-Length header. If I miss it out, I get response from Graph that header is missing.


I realised there is one casue for all this. Deluge invokeurl function is inserting a header and footer in to the byte stream. When I remove that after upload, the file opens normally.

59 bytes at the beginning:

--kH7EE3nxZTAn4hcySXH7cXXpau29ZC70XTWLHl
Content-Disposition: form-data; name="content"; filename="Isabelle blank prescription.docx"
Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document
Content-Transfer-Encoding: binary


46 bytes at the end:

--kH7EE3nxZTAn4hcySXH7cXXpau29ZC70XTWLHl--


This is why it works fine in Postman but not Zoho Deluge. I'm unsure how to proceed but seems its a fault in Deluge. However I have now seen this is a problem on other platforms.

Any ideas would be welcome!

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.