I tried using BackgroundDownloader class to download file from secure FTP server, but it doesn't download and also didn't throw any exception.
The below GetResponseInformation() is returning null.
I'm providing input URL as below:
ftp://username:password#hostIP/test.pdf
Code below:
Uri uri = new Uri(ftpUrlBox.Text.Trim());
StorageFile storageFile = await pickedFolder.CreateFileAsync("DownloadedFile.pdf", CreationCollisionOption.ReplaceExisting);
BackgroundDownloader backgroundDownloader = new BackgroundDownloader();
DownloadOperation downloadOperation = backgroundDownloader.CreateDownload(uri, storageFile);
ftpBar.Visibility = Visibility.Visible;
await downloadOperation.StartAsync();
ftpBar.Visibility = Visibility.Collapsed;
ResponseInformation responseInformation = downloadOperation.GetResponseInformation();
ftpStatusText.Text = responseInformation != null ? responseInformation.StatusCode.ToString() : string.Empty;
Kindly help how to download and upload from and to secure FTP server in UWP.
Note: If I use some 3rd party nuget library, FTP(S) download is working. But not with above UWP code.
Related
I have a problem that is still unclear: I am trying to upload an image from Xamarin via the API. I check the code for the OK message, but the image can't be uploaded to the Server, I tried to test the API on Postman, swagger, it works fine. I checked read_external_storage and write_external_storage
async void pickimg_Tapped(System.Object sender, EventArgs e)
{
var pickResult = await MediaPicker.PickPhotoAsync();
var content = new MultipartFormDataContent();
content.Add(new StreamContent(await pickResult.OpenReadAsync()), "file", pickResult.FileName);
var httpClient = new HttpClient();
var responses = await httpClient.PostAsync("https://api.com/api/UploadFileFeeds", content);
lb_status.Text = responses.StatusCode.ToString();
}
I check the responses value returns OK. However I can't find the image on the Server's folder. Note that when I test on Postman vs swagger, the image is saved on the Server. What did I do wrong? Ask for a solution from everyone
I wrote a program on UWP that stores text in a .txt file which is then voiced to the client. This worked really well when using an HTTP URI but now that site uses HTTPS the program crashes with the error:
System.Net.Http.HttpRequestException: 'Response status code does not indicate success: 401 ().'
The line that it crashes on is:
Byte[] bytes = await cli.GetByteArrayAsync(uriBing);
If I change the link to HTTP the program works fine again. Does anyone know how I can fix this please? Or is it just not possible?
var uriBing = new Uri(#"https://mydomain/net/hal2001/Actions/HALSpeak/speak.txt");
//set storageFolder as the location of the local app storage folder.
StorageFolder storageFolder = ApplicationData.Current.LocalFolder;
//Create a local file to be used to write the URL file to.
StorageFile sampleFile2 = await storageFolder.CreateFileAsync("status2.txt", CreationCollisionOption.ReplaceExisting);
//Write to local file the value stored in the URL file so they match.
var cli = new HttpClient();
Byte[] bytes = await cli.GetByteArrayAsync(uriBing);
If Have tried the following but still not happy.
HttpClientHandler handler = new HttpClientHandler();
handler.Credentials = new System.Net.NetworkCredential("username", "pass");
HttpClient cli = new HttpClient(handler);
I checked the IIS server application > SSL Settings and SSL Settings is set to 'Require SSL' with client certificates set to Accept.
I am trying to download a 1GB file from blob storage into the client. I used before Memory Stream and I get OutOfMemory exception.
now I am trying to open a read stream from the blob and send it directly to the client.
[HttpGet]
[ResponseType(typeof(HttpResponseMessage))]
public async Task<HttpResponseMessage> DownloadAsync(string file)
{
HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
var stream = await blob.OpenReadAsync("container", file);
result.Content = new StreamContent(stream);
return result;
}
The file is downloaded correctly, but the problem is: The code download the complete stream in the client, then the client sees the downloaded file.
I wanted the client to see the file as being downloaded, so the user knows that he is downloading something. Not just blocking the request and wait till it finished.
I am using FileSaver in Angular2:
this.controller.download('data.zip').subscribe(
data => {
FileSaver.saveAs(data, 'data.zip');
});
Has anybody an idea how to fix it?
Thank you!
To fix it you'd need to use the following javascript code instead:
var fileUri = "http://localhost:56676/api/blobfile"; //replace with your web api endpoint
var link = document.createElement('a');
document.body.appendChild(link);
link.href = fileUri;
link.click();
And then in your backend, make it like so:
HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
var stream = await blob.OpenReadAsync("container", file);
result.Content = new StreamContent(stream);
result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
{
FileName = "data.zip"
};
result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
return result;
I had the same problem.
The Solution I sorted out was -
First thing, the expected behaviour can occur only when client tries to download the file from blob and usually I prefer downloading the file from the client itself.
As in your case, try to get file blob uri and do some operations as below to open file in browser using Angular Router or simply window.location.href.
window.location.href = “https://*/filename.xlsx”
This worked for me.
I'm trying to copy a user profile picture from an external service onto my firebase server. So far I have:
final File file = await new File.fromUri(Uri.parse(auth.currentUser.photoUrl)).create();
final StorageReference ref = FirebaseStorage.instance.ref().child("profile_image_${auth.currentUser.uid}.jpg");
final StorageUploadTask uploadTask = ref.put(file);
final Uri downloadUrl = (await uploadTask.future).downloadUrl;
// add user profile picture url to user object
final userReference = FirebaseDatabase.instance
.reference()
.child('users/' + auth.currentUser.uid);
userReference.set({'photoUrl': downloadUrl});
The very top line gives me the error: Unsupported operation: Cannot extract a file path from a https URI
What is the correct way to do this? Should this even be done client-side? (Should I just be passing this url to firebase and use a function to download it server-side?)
File only supports files on a file system.
To load content using HTTP use the http package.
See also https://flutter.io/networking/
var httpClient = createHttpClient();
var response = await httpClient.get(url);
and then get the data from response.body,
or
var response = await httpClient.readBytes(url);
to get it as binary (Uint8List)
See also https://www.dartdocs.org/documentation/http/0.11.3+14/http/Client-class.html
In web App, there is an Input Tag to upload file. In windows phone, It seems it is different. I need hlep on writing HttpWebRequest code to upload file to remote server ( if possible to skydrive). Can you show me how to solve this problem.
1) Upload file from Windows phone.
2) How would I handle the uploaded file on server-side If I use Asp.net.
Thanks.
Something like this. I suggest you ask about how to handle it on the server side in its own question with a different set of tags.
var uri = "http://example.com/some_applette"
var request = HttpWebRequest.create(uri);
request.Method = "POST";
request.ContentType = "image/jpeg"; // Change to whatever you're uploading.
request.BeginGetRequestStream((result1) =>
{
using (Stream stream = request.EndGetRequestStream(result1))
{
// Bytes contains the data to upload.
stream.Write(bytes, 0, bytes.Length);
}
request.BeginGetResponse((result2) =>
{
var response = request.EndGetResponse(result2);
// Optionally handle the response.
var responseStream = response.GetResponseStream();
...
}
}, null);