locked
How to process the StorageItems from share source

    Question

  • I share the file from Photo(Built in OS) to my app.

    In v9200 version, storageItems[i].path is always empty and then getThumbnailAsync API will return error.

    It works normally in v8400 and file path is not empty. 

    shareOperation.data.getStorageItemsAsync().then(function (storageItems) {
            for (var i = 0; i < storageItems.size; i++) {
                storageItems[i].getThumbnailAsync(Windows.Storage.FileProperties.ThumbnailMode.picturesView, 400).then(function (thumbnail) {
                    ...
                }, function (error) {
                    ...
                });        
            }
        );

    Is there a workaround or the method to process storageItems?

    Thanks!

    • Edited by kkkccc Monday, August 6, 2012 10:19 AM
    Monday, August 6, 2012 8:16 AM

All replies

  • Can you provide a simple repro of the problem (perhaps using the samples)?

    -Jeff


    Jeff Sanders (MSFT)

    Tuesday, August 7, 2012 8:30 PM
    Moderator
  • Hi,

    I'm running Photo(built in OS) and Share target apps JavaScript version. The received storageItems cannot  get the thumbnail by using getThumbnailAsync API.

    First, add code to target.js(at line 96)

    if (shareOperation.data.contains(Windows.ApplicationModel.DataTransfer.StandardDataFormats.storageItems)) {

    shareOperation.data.getStorageItemsAsync().then(function (storageItems) { for (var i = 0; i < storageItems.size; i++) { storageItems[i].getThumbnailAsync(Windows.Storage.FileProperties.ThumbnailMode.picturesView, 400).then(function (thumbnail) { // process to thumbnail }, function (error) { // error handling }); } );

    }

    reproduce step:

    1. Open Photo app(built in OS), choose some local photo
    2. Launch share charm, share to sample Share Target app
    3. Check if getThumbnailAsync() works normally

    The getThumbnail will return some errors.

    It only happened in Win8 v9200.

    Links to MSDN sample apps mentioned above:

    Share Source: Photo 

    Share Target: http://code.msdn.microsoft.com/windowsapps/Sharing-Content-Target-App-e2689782

    Thanks


    • Edited by kkkccc Wednesday, August 8, 2012 2:16 AM
    Wednesday, August 8, 2012 2:13 AM
  • The Photo app is not providing a thumbnail, that is why you cannot retrieve it.

    Download and convert the sharing source and sharing target sample applications and you will see how the thumbnail functionality is working correctly.

    -Jeff


    Jeff Sanders (MSFT)

    Wednesday, August 8, 2012 1:04 PM
    Moderator
  • Hi,

    I am seeing that the path is empty.  Even the ShareTarget example also has empty path.  Is that the way it suppose to be?  

    1. Open Photo app(built in OS), choose some local photo
    2. Launch share charm, share to sample Share Target app

    put debug breakpoint in target.js

    if we look at storageItems index 0, the path is "".  The folderRelativeId is "0\\capricorn.jpg".  The particular file is inside Photo app's "Pictures Library".  

            if (shareOperation.data.contains(Windows.ApplicationModel.DataTransfer.StandardDataFormats.storageItems)) {
                shareOperation.data.getStorageItemsAsync().done(function (storageItems) {
                    var fileList = "";
                    for (var i = 0; i < storageItems.size; i++) {
                        fileList += storageItems.getAt(i).name;
                        if (i < storageItems.size - 1) {
                            fileList += ", ";
                        }
                    }
                    displayContent("StorageItems: ", fileList, false);
                });
            }

    

    screenshot:

    Saturday, September 8, 2012 10:51 PM
  • I don't know specifics of how the Photo app was created, but it would make sense that the path would be blank or null. The Photo app is able to draw resources from several different sources (e.g., your local computer and SkyDrive). For anything not on your current computer, there can't be a path to the image. I think it's better to assume there won't be a path, even when the source might be on your local computer somewhere. After all, the original picture might be stored locally in a place that your app can't access (e.g., in the isolated storage of a different app).

    Does the path being blank cause problems?

    Monday, September 10, 2012 1:08 PM
  • Thanks for the reply Brian.  The blank path does cause problems because how can we create a

    BackgroundTransferContentPart using that storageItem?  getStorageItemsAsync gives us storageItem/s and we want to create BackgroundTransferContentPart and use

    BackgroundUploader createUploadAsync.

    With things shared from Photo app, how can we do that or what's the approach?

    Thanks

    Wednesday, September 12, 2012 4:57 AM
  • Are you looking to replace the file returned from the Photo app, or are you looking to upload the returned file somewhere else.

    If you're trying to replace the file, then you are correct: without the path, you won't be able to do that.

    If you're trying to upload the file somewhere else, then you shouldn't need the URI of the picked file. BackgroundUploader.createUploadAsync takes a URI argument, but it's the URI of the destination, not of the source. Check out this example on how to create a multi-part upload: http://msdn.microsoft.com/en-us/library/windows/apps/xaml/windows.networking.backgroundtransfer.backgroundtransfercontentpart.aspx

    Hope that helps.

    Wednesday, September 12, 2012 12:28 PM
  • We want to upload file and question was based on the link you provided.  From the Photo app storageItem, we need to create BackgroundTransferContentPart and use BackgroundUploader createUploadAsync.  How can that be done since the Photo app doesn't provide a "valid" storageItem?  How can the contentparts from Photo app be created?  Thanks
    Thursday, September 13, 2012 5:29 AM
  • I have the same issue.  I'm get the StorageFile from the shareOperation's data.  However, its path is always empty and getThumbnailAsync always returns default thumbnail pic if mode == singleItem or throws if mode is anything else.  

    Any idea how to get around this issue?

    Sunday, October 14, 2012 9:04 PM