开发者

Uploading a JPEG created from a WriteableBitmap without saving it to the users computer first

I have an application that allows users to upload videos to the server and part of the process is to create a thumbnail image on the client that will be used for the video when loaded on the server. I have a writeablebitmap that I want to convert to a jpeg and upload to the server.

Is it possible to do this without saving the jpeg to the user's computer first - I do not want to require a trusted app. Is it possible to store it in isolatedstorage first and then upload it from there as if it is just another file on the user's开发者_StackOverflow社区 computer?

thanks Michael


You will have to save the file before uploading, but it is certainly possible to save it to Isolated Storage rather than the general file system.

There's a Microsoft Quickstart on Isolated Storage that writes an image.

the name of an image and the actual image file itself are saved in isolated storage. The image name is saved in a setting named userSettings with a key of userImage. Saving the image name is not required, but it is saved as a convenience. The image file is saved in a directory named Images and is named UserImageFile.jpg.

The OpenFile method;

Opens a file at a specified path using the specified sharing and access options. This method returns an IsolatedStorageFileStream object that contains the file's stream.

There's some code you can download which should get you started.


I implemented a solution that allows me to take a WriteableBitmap, convert it to a JPEG using FJCore and write it to a MemoryStream and send it to the server.

FluxJpeg.Core.Encoder.JpegEncoder encoder = new FluxJpeg.Core.Encoder.JpegEncoder(img, quality, stream);

see: Using FJCore to encode Silverlight WriteableBitmap

Then I found a great FileUploader class which I modified to upload a MemoryStream avoiding having to create a local file first.

ORIG:

public void StartUpload(FileInfo file)

MODIFIED:

public void StartUpload(Stream fileStream)

see: http://www.codeproject.com/KB/silverlight/SL4FileUploadAnd_SL4_MVVM.aspx

On the server I used the FileUpload.ashx described in the link above to accept the chunks of the stream and write them to a file on the server.

Calling the FileUpload.ashx using a HttpWebRequest, the MemoryStream is sent up in chunks until the end of the stream is reached.

As they bytes are received on the server they are written out to a file in a specified location.

  • Michael
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜