How to upload a file using multipart/related in postman? - post

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.

Related

Uploading an image from iOS to Azure File Share

I have found documentation for uploading an image from iOS to a blob container in Azure - https://learn.microsoft.com/en-us/azure/storage/blobs/storage-ios-how-to-use-blob-storage
using the https://github.com/Azure/azure-storage-ios library
But I wish to upload directly to a file share. Is there a way to do this?
It needs to be implemented using SAS authentication.
Unfortunately I am not familiar with iOS programming thus I will not be able to provide you any code. However you can use the steps below to write code.
Assuming you have a SAS URL for the file share in which you wish to upload the file, you can simply use Azure Storage REST API to upload the file in a file share. You should be able to use built-in HTTP functionality in the programming language of your choice to do that.
Let's assume that you have a SAS URL for the file share in the following format: https://<account-name>.file.core.windows.net/<share-name>?<sas-token>.
First thing you would need to do is insert the file name that you wish to upload in this SAS URL so that you get a SAS URL for the file. Your SAS URL would look something like: https://<account-name>.file.core.windows.net/<share-name>/<file-name>?<sas-token>.
Next you would need to create an empty file. You will use Create File REST API operation. Do not worry about the Authorization request header there as it is already included in the SAS. Only request header you would need to include is x-ms-content-length value of which should be the size of the file you want to upload. This will create an empty file having size as that of the file you want to upload.
Once this operation completes, next you would need to upload the data in the empty file you just created. You will use Put Range operation. The request headers you need to include are x-ms-range (value of which should be bytes=0-file-length - 1) and Content-Length (value of which should be the length of your file). The request body will contain the file contents.
Using these steps you should be able to upload a file in a file share.

Microsoft Graph API, corrupted files

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.

Unable to set profile picture using Graph Explorer

I'm trying to update my profile picture using Microsoft Graph Explorer (v1.0) but I'm unable to do it, I'm always getting the following error :
An internal server error occurred. The operation failed., The file you chose isn't an image. Please choose a different file.
The problem is that the file I'm trying to update my picture with is an image inserted in the request body (a base64 representation of it, I used this site in order to get it: https://www.base64-image.de/).
I'm also using the header Content-Type with the value image/jpeg and I think that, as I'm logged, I don't need the authorization header.
The URL I'm using is: https://graph.microsoft.com/v1.0/me/photo/$value
This endpoint takes the raw image as input, not a base64 encoded version. From the documentation:
Request body
In the request body, include the binary data of the photo in the request body.
Since it isn't possible to stream a file like this using Graph Explorer, updating the photo isn't supported by Graph Explorer.

Rails ActiveStorage how to Fileupload via REST API

How can I upload a file from an external service or app (iOS App, Go App, etc) to a Rails REST API which uses Active Storage local file storage?
All the tutorials I can find use HTML forms. I'd like to upload my files via a POST request to the Rails API. The main thing I am uncertain about is what headers and what kind of format I need to send the files in to the backend.
The solution was to just send normal form-data. I used Postman for testing which works great for file uploads as well http://getpostman.com
Base64 is useful for you, You can decode base64 then generate temp file and upload that file.

paperclip upload a file to S3 from remote_url and token needed

I'm writing an importation function from a remote service to our app which uses S3. I connect to an api using OAuth as authentication, so every request I make I need to attach the token in the header. The attachments must be copied to S3 and the model is using paperclip.
I read the file from the api (say origin) with a GET method which returns a response with the body filled in with the content and the header with filename and other information.
Q: Now that I have the body of the file in plain text, how do I store it in S3 (destination) with paperclip?
Alternatively
Q: I could upload the file to S3 (destination) using remote URL(as described here), but how do I attach the token to the paperclip request to the (origin) api?
thanks
You need to create an s3.yml in your config directory... Here's a detailed tutorial in setting up paper clip with rails 3: http://doganberktas.com/2010/09/14/amazon-s3-and-paperclip-rails-3/
I would suggest you use a conversion tool to generate either a PDF or an editable document, then upload that to s3... Here's a good PDF gem: http://ruby-pdf.rubyforge.org/pdf-writer/ and even a railscast to help: http://railscasts.com/episodes/78-generating-pdf-documents
and here's an rtf gem: https://rubygems.org/gems/rtf
Since you have the raw data that should work.

Resources