MS GRAPH API Upload v1.0 endpoint corrupts DOCX - postman

Was trying to upload docx files through a golang server using MS graph API, and although I was able to upload pdfs, when I tried uploading docx files the files were being corrupted when sent over. If I upload the same file through the OneDrive website, there would be no problems.
To isolate the issue I tried making the API calls through postman using a link like:
https://graph.microsoft.com/v1.0/users/pqv2-dev-svc#novacoast.com/drives/{drive-id}/items/{item-id}:/filename.docx:/content
used a bearer token.
the additional header of Content-Type of which I have tried the values:
text/plain
application/x-www-form-urlencoded
application/vnd.openxmlformats-officedocument.wordprocessingml.document
and uploaded the file with the form-data option under the body tab but with no luck, the file always gets corrupted.
Any ideas?

[Resolved] Was sending file as form-data instead of binary!

Related

How to limit Content-Type header in Amazon s3 Pre-Signed Url

We have a client incorrectly setting the Content-Type to application/json when uploading a pdf file to s3. This results in the client library we use to download the file to give it the wrong extension, also happens when you download the file from the s3 console, even though it has .pdf as the suffix, it downloads to .json.
Is there anyway to prevent clients from doing this? The Content type should always be application/x-www-form-urlencoded from my understanding.

How to get content of the post request file POSTMAN

I have a problem with sending files to some API. When I do it via my server some pdf files send correctly but some not. But when I send the same pdf via POSTMAN everything works just fine. I am not sure what is the reason (probably POSTMAN encodes it into base64 but from my server, I send it in binary - just a guess). Is there a way to get the sent request file content from postman so that I can imitate it and compare with the request on my server?

Microsoft Graph API - Error: The Content-Range header length does not match the provided number of bytes

I am trying to upload a file to the Shared Documents library of my SharePoint website. The files are of type PDF and HTML. I am running a Cold Fusion development environment and using CFHTTP commands to execute HTTP requests. I have been able push a POST command and a PUT command to the proper endpoints listed on this link below:
Link: https://learn.microsoft.com/en-us/graph/api/driveitem-createuploadsession?view=graph-rest-1.0#best-practices
I do not understand why but the first section that mentions the HTTP requests for creating an upload session is different than what was used in the example a little further. For my project, I am using the endpoint:
"/{variables.instance.microsoftGraphAPIURL}/drive/root:/{item-path}:/createUploadSession"
P.S. variables.instance.microsoftGraphAPIURL is a variable to a microsoft graph endpoint to our Sharepoint website
With better luck using PUT commands than POST commands for creating an Upload Session. I am able to receive an uploadURL, but the issue comes with trying to upload the file. For the file upload, I am trying to upload a file in the same directory with a file size of 114992 bytes. I keep getting "The Content-Range header length does not match the provided number of bytes." whenever I run my Put command to upload the file.
Thus, my Content-Range is "bytes 0-114991/114992" and my Content-Length is "114992". For the image below, I replaced the file with a pdf, but the original file was an HTML page at 114992 bytes. I want to use a resumable upload session to have one function for uploading image, HTML, and PDF files.
If anyone could tell me if there is an issue with my content headers or my upload session http request or anything else that is causing my issue, that would be amazing! Thank you.

How to upload a file from a URL as multipart/form-data in Postman

I have an API endpoint that accepts multipart/form-data file upload. I managed to upload a local file to it with Postman using the File option as below:
Now how can I upload a file that is hosted at a given URL using Postman without manually downloading it and then selecting its filename as in the above screenshot? I'm hoping to somehow GET the URL, store the binary data, and upload to the endpoint, all within a Postman collection.
One of the answers from Postman community issue:
Using Postman’s pre-request script:
Download the content from URL
Convert it to binary
Assign the binary value to a dynamic variable
Use the variable within your request

Upload document in postman

Iam facing some challanges by uploading a document in postman. The steps how to upload a document by the body and choosing form-data then you add file and change it to file instead of tekst. This goes fine and when I excute the call it goes through. But when I close the postman call and try to open it again and excuted it gives me 400 error code. When I look into the body and espacially by the form-data it shows that no file is choosing. So postman is not saving the path where the document is located. In this case I have to added everytime when I want to run the request.
The quastion is how do I fix this problem. Postman is not saving the location of the document.
Thanks in advance