I am using this document to upload excel files to OneDrive https://learn.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_put_content?view=odsp-graph-online.
The API call in Postman is:
https://graph.microsoft.com/v1.0/me/drive/root:/FolderA/cn.xlsx:/content?
Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
The issue is that the file got uploaded, but it is always being corrupted. The reason I believe is that the file is being convert to text file first, and then convert back to excel file due to the file extension (xlsx).
Does anyone know how I can get around this issues? Thank you very much.
Postman's snippet
Postman's snippet 2
Try to put 'text/plain' in content-type when you upload the bytes. This resolved my problem.
Related
When I am trying to upload image using graph EndPoint then images are getting corrupted.
Endpoint - PUT https://graph.microsoft.com/v1.0/drives/{drive_id}/items/{item_id}:/{file_name}:/content
Anything I am missing here?
SharePoint Message When trying to view uploaded (through above code)image. Tried without encoding as well. Even file name is not encoded then also its same behavior.
Note - This issue is with only images. Other files like PDF, CSV are working fine.
Changing form-data to binary solved my problem.
I am downloading data in excel format in my Rails 4 app using send_data method as mentioned below.
send_data collection.to_csv(col_sep: "\t"),
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
filename: 'filename.xls'
I am able to download the data, but while opening the downloaded excel file, i am getting below warning message.
The file format and extension of 'file.xls' don't match. The file could be corrupted or unsafe.
Unless you trust its source, dont open it. D want to open it anyway?
Even it is warning, it would cause confusion to customers while downloading and opening the file. Any one has any clue about, what is it about and how could it be fixed?
Any help would be greatly appreciated.
It isn't an XLS file you are creating but a CSV file, so you should change the filename to 'filename.csv'. It will still be openable in Excel.
You might also want to change the MIME type to text/csv.
The correct MIME for an Excel file can be found here.
For my project need, I need to convert MS format documents in to pdf. I started exploring microsoft graph API. For easiness I started with graph explorer(using my corporate and personal login) on https://developer.microsoft.com/en-us/graph/graph-explorer.
I have added sample document in drive and using https://graph.microsoft.com/v1.0/me/drive/root/children, I got itemId of my file.
Now, I am trying to convert it into pdf using https://graph.microsoft.com/v1.0/me/drive/items/{itemId}/content?format=pdf. But I am always getting response as Failure - Status Code 0
Anyone has an idea how to fix this issue?
Here is an attached screen shot of microsoft graph explorer
Note: I found similar problem here but it is not solved
According to your description, I assume you want to convert .docx file to pdf using Microsoft graph API.
Based on my test, we can use https://graph.microsoft.com/v1.0/me/drive/items/{itemId}/content?format=pdf.
It will return a failure response when run it in graph explore. However, when we use the develop control panel, we can get this request and response.
Location properties are in the response headers. It is the address of the converted file.
We can use this URI to review or download the document that converted.
The request URL:
https://graph.microsoft.com/v1.0/me/drive/items/{itemId}/content?format=pdf
The response may like this:
I want to upload a text file to OneDrive API.I don't have any idea about multipart/related. Can any one suggest me how to put below data in postman to upload a file.
I resolved this issue.We need to provide Authorization & Content-Type in header and provide the remaining information in body as raw and select content-type as Text.
I have to send .csv file to remote server through REST in rails.
I had tried post_form of Net::HTTP and made form as multipart true, by this file get transfer (seen in parameters at both side) but at server side i am not able to read it.
It gives error "No such file or directory."
Please any can tell me is there other way to transfer file.
After finding on this and tried many things i got good solution from that i can send csv file by REST web service.
here is solution...
https://github.com/jwagener/httmultiparty
Also can use REST Client for testing purpose.