I do a WinJS.xhr() call with a responseType of "blob" and the result.response is an image. How do I share that image? The DataTransferManager's setBitmap wants a streamreference. Do I need to record the image to a temporary file and then do a Windows.Storage.Streams.RandomAccessStreamReference.createFromFile()
? If so, how do I write the image to a StorageFile? Thanks.
Asked
Active
Viewed 282 times
0

Jeremy Foster
- 4,673
- 3
- 30
- 49
2 Answers
1
You have two choices:
- Writing the file to disk. See this question for details
- Create a multiple use blob from the XHR response. See MSDN for details.
The second option stops you from having to write the file to disk if your just sharing it temporarily, but it does some with some memory management to revoke the blob later. With the URL created, you can just assign it to the an img
tags src
attribute.

Community
- 1
- 1

Dominic Hopton
- 7,262
- 1
- 22
- 29
-
Thanks, Dominic. That process for writing the blob to disk seems painful. I guess that's what's required though, right? – Jeremy Foster Dec 01 '12 at 02:02
-
If you need to get it to disk, yes. If you just wanna use the blob in multiple places in your UI for a few minutes, or an app run, and don't want the cache, then the createObjectUrl, will give you a URL you can assign to multiple image tags. – Dominic Hopton Dec 01 '12 at 02:03
-
I don't ultimately need to get it to disk. I ultimately need to get it to a stream that is compatible with the e.request.data.setBitmap() method inside the DTM so I can share. In the link you sent me in #2, are you saying I can use the "ms-stream" response type to get a stream that can be passed in to that setBitmap() method? – Jeremy Foster Dec 01 '12 at 05:07
-
I think so - but I'm not a dtm expert. – Dominic Hopton Dec 01 '12 at 06:07
0
Alternative answer to this old question, if the goal is to share an image without saving it,
Windows.Storage.Streams.RandomAccessStreamReference.createFromUri(targetImageSrc);
Should achieve the same result, create the stream from the uri
instead of a file
.
Although, this function might not have been available back then.

Ringo
- 850
- 9
- 24