Asked by:
Windows store app - Probem with opening files that was uploaded to ftp server

Question
-
I have this below code that uploads a file to my ftp server.
FileOpenPicker picker = new FileOpenPicker(); picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary; picker.FileTypeFilter.Add( ".png"); picker.FileTypeFilter.Add( ".jpeg"); picker.FileTypeFilter.Add( ".jpg"); picker.FileTypeFilter.Add( ".bmp"); StorageFile file = await picker.PickSingleFileAsync(); IRandomAccessStream fileStream = await file.OpenAsync(FileAccessMode.Read); var reader = new Windows.Storage.Streams.DataReader(fileStream.GetInputStreamAt(0)); await reader.LoadAsync((uint)fileStream.Size); byte[] pixels = new byte[fileStream.Size]; using (Stream requestStream = await request.GetRequestStreamAsync()) { await requestStream.WriteAsync(pixels, 0, pixels.Length); await requestStream.FlushAsync(); }
This code works and i see the file on the server. But when i download the file to open it , i get an error saying that the file is not a valid .bmp file.
I think the uploading process is the reason why the file ends up not being open-able.. Does anyone know what the problem might be? and how i should fix it?
Monday, August 26, 2013 7:31 AM
All replies
-
Is the file on the server the same size as the file that you uploaded from the client? It sounds like they are likely different.
Matt Small - Microsoft Escalation Engineer - Forum Moderator
If my reply answers your question, please mark this post as answered.
NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.Monday, August 26, 2013 12:33 PMModerator -
Yes it is.Monday, August 26, 2013 3:04 PM
-
if you download the file to the desktop using a FTP client, can you open it?
Matt Small - Microsoft Escalation Engineer - Forum Moderator
If my reply answers your question, please mark this post as answered.
NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.Monday, August 26, 2013 3:49 PMModerator -
Nope my get the same error.Monday, August 26, 2013 7:34 PM
-
THis is a screenshot of it.
i think i need to use Binary reader to read the bytes but i dont know how.- Edited by kalel111 Monday, August 26, 2013 10:50 PM
Monday, August 26, 2013 8:00 PM -
Change the file extensions to .bin and open in Visual Studio, compare the two. If they are different, then there's something causing that difference. You would have to get a network trace and compare the bytes being sent with the bytes that are inside the file. ETW network tracing might also help here. It's possible that you have a firewall or other device in-between the client and server that is causing this problem. Does it happen if you try to upload to a different machine?
Matt Small - Microsoft Escalation Engineer - Forum Moderator
If my reply answers your question, please mark this post as answered.
NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.Wednesday, August 28, 2013 1:09 PMModerator