locked
Share Multiple Images with one share action

    Question

  • Need help with this here is my share code

    function dataRequested(e) {
        var request = e.request;

        // Title is required
        var dataPackageTitle = document.getElementById("titleInputBox").value;
        if ((typeof dataPackageTitle === "string") && (dataPackageTitle !== "")) {
            if (imagesurl) {
                request.data.properties.title = dataPackageTitle;

                // The description is optional.
                var dataPackageDescription = document.getElementById("descriptionInputBox").value;
                if ((typeof dataPackageDescription === "string") && (dataPackageDescription !== "")) {
                    request.data.properties.description = dataPackageDescription;
                }
                if (imagesurl.length > 0) {
                    for (var j = 0; j < imagesurl.length; j++) {
                        var loc = imagesurl[j].pictures;
                        var w = document.getElementById("intend");
                        var e = w.innerText = loc;
                        var streamReference = Windows.Storage.Streams.RandomAccessStreamReference.createFromFile(imagesurl[j].pictures);
                        request.data.properties.thumbnail = streamReference;
                        

                        // It's recommended to always use both setBitmap and setStorageItems for sharing a single image
                        // since the Target app may only support one or the other

                        // Put the image file in an array and pass it to setStorageItems
                        request.data.setStorageItems([imagesurl[j].pictures]);

                        // the setbitmap method requires a randomaccessstreamreference
                        request.data.setBitmap(streamReference);
                    }
            }
            } else {
                request.failWithDisplayText("Select an image you would like to share and try again.");
            }
        } else {
            request.failWithDisplayText("No Selection Made Please Ensure You Have Selected An Image and Entered Its Title");
        }
    }

    Tuesday, June 11, 2013 11:32 PM

Answers

  • What are you trying to do? What behavior do you want, and how does that differ from the behavior you are getting?

    The DataPackage can contain only one bitmap (via setBitmap). It can contain multiple bitmap files (via setStorageItems), but that need to be a single collection of StorageItems. It's not clear from your code if that is the case, and your code appears to loop through multiple images and overwrite the DataPackage with the last one rather than collecting them all to add to the same DataPackage.

    See How to share files, Quickstart: Sharing content , and the Sharing content source app sample

    --Rob

    • Marked as answer by Ir2guru Wednesday, June 12, 2013 7:11 AM
    Wednesday, June 12, 2013 7:02 AM
    Owner

All replies

  • What are you trying to do? What behavior do you want, and how does that differ from the behavior you are getting?

    The DataPackage can contain only one bitmap (via setBitmap). It can contain multiple bitmap files (via setStorageItems), but that need to be a single collection of StorageItems. It's not clear from your code if that is the case, and your code appears to loop through multiple images and overwrite the DataPackage with the last one rather than collecting them all to add to the same DataPackage.

    See How to share files, Quickstart: Sharing content , and the Sharing content source app sample

    --Rob

    • Marked as answer by Ir2guru Wednesday, June 12, 2013 7:11 AM
    Wednesday, June 12, 2013 7:02 AM
    Owner
  • Thanks Will See to That....
    Wednesday, June 12, 2013 7:11 AM