I am trying out the one drive graph api to upload folder to my one drive folder.
Using the regular upload works fine.
I'm also testing the resumable upload, which is used for large files. But this is where I'm getting a strange response.
I'm following this link for how to do it: https://learn.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_createuploadsession.
First i get a create an upload session using "https://graph.microsoft.com/v1.0/me/drive/items/xxxxxxxxxx:/filename.txt:/createUploadSession".
This gives me back an uploadUrl value, something like "https://api.onedrive.com/rup/xxxxxxxxxxxxx"
I then make a PUT request to that URL with the correct headers.
The response I receive is a 400 (bad request) with the following text (including the HTML):
<h2>Our services aren't available right now</h2><p>We're working to restore all services as soon as possible. Please check back soon.</p>Ref A: 235A863C95DC45BE98688D905A7DB3C1 Ref B: BUH01EDGE0107 Ref C: 2018-08-28T18:56:52Z
I have been getting this for 3 days now and I can't seem to get hold of any support from Microsoft. According to this website, everything is running: https://portal.office.com/servicestatus
Does anyone know why I'm getting this error?
I found the cause for the error.
I received the error because I provided the authentication token in the header.
For small file uploads it is required, but for large file uploads it is not required.
I was using the same code for PUT, POST and GET requests, where I only pass in the URL and HTTP Content and i would always add the auth headers. But for large file uploads it is not required.
But still a very strange error response to receive for adding unrequired headers.
Related
I have a problem when I upload the large file on Azure. I am working on an ASP.NET Core 5.0 API project.
I have implemented functionality regarding Microsoft recommendation. Moreover, I added a pooling mechanism so the frontend application has another endpoint to check upload status.
Everything works fine when I run locally but I have a problem with a large file on Azure. My API is using Azure App Service Premium P1v3. It returns a 502 bad gateway for large files (above 1GB).
I made a tests and 98 % time consuming is reading stream. From Microsft docs it is:
if (MultipartRequestHelper
.HasFileContentDisposition(contentDisposition))
{
untrustedFileNameForStorage = contentDisposition.FileName.Value;
// Don't trust the file name sent by the client. To display
// the file name, HTML-encode the value.
trustedFileNameForDisplay = WebUtility.HtmlEncode(
contentDisposition.FileName.Value);
streamedFileContent =
await FileHelpers.ProcessStreamedFile(section, contentDisposition,
ModelState, _permittedExtensions, _fileSizeLimit);
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
}
I know there is a load balancer timeout of 230 seconds on Azure App Service but when I test it using postman in most cases 502 is being returned after 30 seconds.
Maybe I need to set some configuration feature on Azure App Service? Always on is enabled.
I would like to stay with Azure App Service, but I was thinking about migrating to Azure App service or allow the Frontend application to upload files directly to Azure Blob Storage.
Do you have any idea how to solve it?
Newset
Uploading and Downloading large files in ASP.NET Core 3.1?
The previous answers are based on only using app services, but it is not recommended to store large files in app services. The first is that future updates will become slower and slower, and the second is that the disk space will soon be used up.
So it is recommended to use azure storage. If you use azure storage, suggestion 2 is recommended for larger files to upload large files in chunks.
Preview
Please confirm whether the large file can be transferred successfully even if the error message returns a 500 error.
I have studied this phenomenon before, and each browser is different, and the 500 error time is roughly between 230s-300s. But looking through the log, the program continues to run.
Related Post:
The request timed out. The web server failed to respond within the specified time
So there are two suggestions I give, you can refer to:
Suggestion 1:
It is recommended to create an http interface (assuming the name is getStatus) in your program to receive file upload progress, similar to processbar. When the file starts to transfer, monitor the upload progress, upload the file interface, return HttpCode 201 accept, then the status value is obtained through getStatus, when it reaches 100%, it returns success.
Suggestion 2:
Use MultipartRequestHelper to cut/slice large file. Your usage maybe wrong. Please refer below post.
Dealing with large file uploads on ASP.NET Core 1.0
The version of .net core is inconsistent, but the idea is the same.
Facing similar issue on uploading document of larger size(up to 100MB) through as.net core api hosted as azure app gateway and have set timeout to 10min and applied these attributes on action
[RequestFormLimits(MultipartBodyLengthLimit = 209715200)]
[RequestSizeLimit(209715200)]
Even kestrel has configured to accept 200MB
UseKestrel(options =>
{
options.Limits.MaxRequestBodySize = 209715200;
options.Limits.KeepAliveTimeout = TimeSpan.FromMinutes(10);
});
The file content is in base64 format in request object.
Appreciate if any help on this problem.
I am attempting to generate a pdf from a SSRS report using URL Access in C#.
(In the business layer behind a WebApi Controller) I create an instance of the HttpClient, assign correct credentials and form the request URL like:
http://sqlserver1/ReportServer/Pages/ReportViewer.aspx?/Clients/Acme/AcmeActivitySummary&rs:Command=Render&rs:format=pdf&Region=west&CutOffDate=10/25/2015
If I put my URL in a browser, it downloads the expected PDF file.
When I execute this URL from the HttpClient instance to return a stream, I get a 401 Unauthorized Error.
If I open up Fiddler to see why...it works as expected.
How do I make this work without having to use Fiddler...and why doesn't it work now?
Somewhere along the lines Microsoft changed the "standard" for URL Access to SSRS. The URL Pattern " http://{Server}/ReportServer/Pages/ReportViewer.aspx?/{Path to Report File} & [commands] & [parameters]
was deprecated in favor of
http://{server}/reportserver?/{path} & [commands] & [parameters].
HOWEVER...the old url pattern will still work 'sometimes'. SSRS will still receive the request at the old 'endpoint' and, if the request can be forwarded it will do so. So a 'normal' request from a browser (or from Fiddler) appears to work just fine. The problem is with the HttpClient request, which SSRS will not forward to the new endpoint...and it just returns the [somewhat confusing] 401 Unauthorized exception...which apparently means "I am not authorized to forward this request" not "you are not authorized to access this resource".
(after losing more time than I care to admit finding this...I thought a post here would be helpful to others.)
I am building a tool to translate some CSV files into XML files and then upload them via the Amazon Web Services to upload products to a market place store.
I am testing the tool and the CSV to XML translation is fine and valid xml is created but I am having trouble calling the AWS services and sending the files. At the moment I can't even succesfully call the AWS service let alone try sending a file.
When I create a HttpWebRequest and try and call the method "GetRequestStream" I get a WebException:
"The remote name could not be resolved https"
There is no inner exception or anything useful to help me.
The properties I have set to the webRequest are
Address - https://mws.amazonservices.co.uk/Action=SubmitFeed&MarketplaceIdList.Id.1=MarketPlaceId&Merchant .................
Headers -
+ Headers {User-Agent: Funkyrox/1.0 (Language=C#; =)
Content-Type: application/octet-stream
Content-MD5: 4BDPHUko1//iVAdb5wr/Vw==
Host: mws.amazonservices.co.uk
} System.Net.WebHeaderCollection
Host -
"mws.amazonservices.co.uk"
Method - POST
RequestUri -
https://mws.amazonservices.co.uk/Action=SubmitFeed&MarketplaceIdList.Id.1=MarketPlaceId&Merchant......................
There are others if needed as well.
When I ping https://mws.amazonservices.co.uk I get a response so I think the it's valid
I can't seem to find really useful examples of how to do this. I downloaded an C# tool from Amazon and have used a lot of the code in there but can't see how to call the service correctly.
Anyone with any ideas?
I'm working on a continuing API project. The current issue at hand is to be able to download my data from the AtTask server in precisely the folder structure they exist in on the AtTask servers. I've got the folder creation working nicely; the data types between Document, Document Folder and Document Version seem to be pretty clear. I am a little disillusioned about the fact that extension isn't in the document object (that I have to refer to the document VERSION for that)... but I can see some of the reason for that from a design perspective.
The issue I'm running into now is that I need to get the file content. I originally through from the API documentation that I'd be able to get to the file contents the same way as the documentation recommends uploading it -- through the handle. Unfortunately, neither document nor docv seem to support me accessing the handle except to write a new file.
So that leaves me the "download URL" as the remaining option. If I build the UI strings from the API calls using my browser, I get a URL with https://attaskURL/document/download?ID=xxxx (and can also get the versionID and such). If I paste the url into the browser where I'm logged in to the user interface of AtTask, it works fine and I can download the file. If, instead, I use my C# code to do so, I get the login page returned as a stream for me to download instead of my actual file because I'm not authenicated. I've tried creating a network credential and attaching it to the request with the username and password, but to no avail.
I imagine there's a couple ways to solve this problem -- the easy one being finding a way to "log in" to the download site through code (which doesn't seem to be the usual network credential object in C#) OR find a way to access the file contents through the API.
Appreciate your thoughts!
It looks like you can use the download URL if you put a session id in the URL. The details on getting a session id are here (basically just call login and a session id is returned in JSON):
http://developers.attask.com/api-docs/#Authentication
Then cram it on the end of your document download URL:
https://yourcompany.attask-ondemand.com/document/download?ID=xxxx&sessionID=abc1234
I've given this a quick test and I'm able to access a document.
You can use the downloadURL and a sessionID IF you are not using SAML authentication.
I have tried it both ways and using SAML will redirect you to the login page.
This is my first time developing this kind of system, so many of these concepts are very new to me. Any and all help would be appreciated. I'll try to sum up what I'm doing as efficiently as possible.
Background: I have a web application running AngularJS with Bootstrap. The app communicates with the server and DB through a web service programmed using C#. On the site, users can upload files and reference them later using direct links. There's no restriction to file type (yet), so just about anything is allowed.
My Goal: Having direct links creates a big security problem for me, since the documents/images are supposed to be private data. What I would prefer to do is validate a user's credentials when the link is clicked, then load the file in the browser using a more generic url path.
--Example--
"mysite.com/attachments/1" ---> (Image)
--instead of--
"mysite.com/data/files/importantImg.jpg"
Where I'm At: Not very far. My first thought was to add a page that sends the server request and receives a file byte stream along with mime type that I can reassemble and present to the user. However, I have no idea if this is possible using a web service that sends JSON requests, nor do I have a clue about how the reassembling process would work client-side.
Like I said, I'll take any and all advice. I'd love to learn more about this subject for future projects as well, but for now I just need to be pointed in the right direction.
Your first thought is correct, for it, you need to use the Response object, and more specifically the AddHeader and Write functions. Of course this will be a different page that will only handle file downloads, so it will be perfectly fine in your JSON web service.
I don't think you want to do this with a web service. Just use a regular IHttpHandler to perform the validation and return the data. So you would have the URL "attachments/1" get rewritten to "attachments/download.ashx?id=1". When you've verified access, write the data to the response stream. You can use the Content Disposition header to set the file name.