Download file to Windows Phone with c# and OneDrive API - c#

Someone knows how to make downloading files to phone?
I made a request and received items:
HttpClient httpClient = new HttpClient();
var response = await httpClient.GetAsync(String.Format("https://api.onedrive.com/v1.0/drive/special/approot/children?access_token={0}", token));
var text = await response.Content.ReadAsStringAsync();
I have them id, and now i must do nex request:
https://api.onedrive.com/v1.0/drive/items/{ID}/content
But how to make downloading a file in the local storage application? (file format is .txt)

Once you've made the request to download the content, you should receive a HTTP 302 response. To download the file, you'll need to follow the URL provided in the Location header of the response. You can then use the FileSavePicker class to save the file locally. More info on the FileSavePicker can be found at https://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.pickers.filesavepicker.aspx . I hope that helps.

Related

Download pdf files from a link

i am working on .Net app that need to download research files from the given link. i checked that most of the published portal show the pdf files on pdf viewer and there to download the file, no .pdf link that can download directly. Can someone recommend how to download files in such cases. example i want to download the pdf from following link https://ietresearch.onlinelibrary.wiley.com/doi/pdf/10.1049/iet-epa.2019.0877 .
As #Philip-Stuyck mentioned in the comments, you can use HttpClient to download the file. Here is the sample code:
using var client = new HttpClient();
var uri = new Uri("https://ietresearch.onlinelibrary.wiley.com/doi/pdf/10.1049/iet-epa.2019.0877");
await using var s = await client.GetStreamAsync(uri);
await using var file = File.Create("iet-epa-localcopy.pdf");
await s.CopyToAsync(file);

Downloading youtube video info

I am trying to download response from this url
http://www.youtube.com/get_video_info?html5=1&video_id=sFwcLC5HC9I
The file it returns can be downloaded from browser, but when I try to save it with c# webclient I get only error message.
errorcode=180&status=fail&reason=HTTP+is+not+supported.
Is there any other way to download file from the API without using HTTP?
What have I tried (a is instance of WebClient):
byte[] policko = a.DownloadData("http://www.youtube.com/get_video_info?html5=1&video_id=sFwcLC5HC9I");
a.DownloadFile("http://www.youtube.com/get_video_info?html5=1&video_id=sFwcLC5HC9I", "filename");
a.DownloadString("http://www.youtube.com/get_video_info?html5=1&video_id=sFwcLC5HC9I");
The response you got indicates that HTTP is not supported for this API call. The next natural choice is HTTPS.
https://www.youtube.com/get_video_info?html5=1&video_id=sFwcLC5HC9I

HttpContext.Current.Request.Files[0].FileName returning blob for image files

I am sending a file as part of the FormData from AngularJs to .NET Web API as follows:
AngularJS:
var cabinetFormData = new FormData();
cabinetFormData.append('file', file);
Sending the above FormData as a parameter in the service call to .Net WebAPI
.NET:
var httpRequest = HttpContext.Current.Request;
var fileRequest = httpRequest.Files[0];
While receiving the request on the server side, the fileRequest.FileName is always showing up as "blob" for any image files. Rest of the content is showing up fine. Getting proper File names for other format's like .pdf and .xml. I have checked the input, and it's sending all the formData.
What am i doing wrong ?
I would post this as a comment, but I don't have the rep yet..
If you're using Firefox when you see this issue, these links might help you out:
Uploaded file comes in as blob if not on localhost? asp.net mvc4 using IIS express
https://groups.google.com/forum/#!topic/jquery-fileupload/RjfHLX2_EeM
:)

How to get video file stream from embed url in c#

I tried this below code but video is not playing.
var httpClient = new HttpClient();
var data = await httpClient.GetByteArrayAsync(new Uri("http://www.youtube.com/embed/iRFE-sKOp4I"));
var file = await KnownFolders.MusicLibrary.CreateFileAsync("myfile.mp4", CreationCollisionOption.ReplaceExisting);
var targetStream = await file.OpenAsync(FileAccessMode.ReadWrite);
await targetStream.AsStreamForWrite().WriteAsync(data, 0, data.Length);
await targetStream.FlushAsync();
targetStream.Dispose();
Any one please help me to how to save download..thankyou
I agree with #x..., If you want to download video from Youtube, you need to install the YoutubeExtractor.
But with that same code i can't to download different website videos.
I tested your code with a video download uri "http://video.ch9.ms/ch9/9b56/4f2d0b4d-ea37-4525-8833-128ad6e69b56/uwp01SeriesIntro.mp4", it works fine.
Actually I want to download openload.co/embed/EHmDelqNx94 video is there any possibility..
I just took a look at this video, I find this a web named openload, and this web service share free without limits, but you need to use the develop Api of it. For downloading, you can refer to the download APIs here.
the video url appears after click on play button, is there any way to handle click event by httpclient or any other clients
From the official document of this web, I found this:
get a download link by using download ticket.
You can refer to Download Link.
Update:
i tried openload api, but when get download link it showing captcha error, can you please help me for this
I just reproduced your problem, this is because your source for download is not a public source, it needed authentication. When you get the Download Ticket for download, although the Api said API-Login and API-Key are not required, you need to use the full path https://api.openload.co/1/file/dlticket?file={file}&login={login}&key={key} to get an authenticated ticket, then you can use this ticket to get the download URL.

Amazon S3 Low Level API uploading Large files

I am using Amazon S3 Low Level API for uploading Large Video File, I am following This link
When I am upoading the file, its giving me exception
The XML you provided was not well-formed or did not validate against our published schema
I have checked Inner Exception and its saying this
The remote server returned an error: (400) Bad Request.
at this line
CompleteMultipartUploadResponse completeUploadResponse =
s3Client.CompleteMultipartUpload(completeRequest);
and this is how I am making my S3Client
IAmazonS3 s3Client = new AmazonS3Client(accesskey, secretKey, Amazon.RegionEndpoint.USEast1);
I also tried changing bucketname like bucketname/filename.mp4,but its giving exception
The specified upload id is not valid
I also tried some other file(doc and pdf) it is also giving XML exception.
Is there any good alternate approach for uploading Large Video files(Around 200-500MB)?
I've found a similar problem during a MultiPart upload using the sample code in the doc. I've found that the ETag list is mandatory for the CompleteMultipartUpload part - which is not in the documentation sample.
This link has a better explanation of the multi-part upload process: s3 multipart upload
I used to send archives to S3 (around 100-300MB). My code looked like this:
AmazonS3Client s3client = new AmazonS3Client(accessKey, secretKey);
s3Client.PutObject(new PutObjectRequest {BucketName = destinationBucketName, FilePath = myFilePath, Key = Path.GetFileName(myFilePath)});
That's it basically. I had retry-policy and exception handling around that, but this is the core. So just simple PutObject function without any multipart uploads works find for such file-sizes.

Categories

Resources