OceanLabs / iOS-Print-SDK

iOS Print SDK. Easily add print on demand functionality to your app within minutes! Print Postcards, Magnets, Photo Prints, Posters, Stickers, T-Shirts, PhotoBooks, etc.
https://www.kite.ly
111 stars 33 forks source link

Using URL OLAsset returning error #279

Open BillyJohn3 opened 7 years ago

BillyJohn3 commented 7 years ago

Hey again, Our app users each have a set of images stored on aws that I would like displayed in the KiteViewController add-on to our app.

What I',m doing currently is getting the list of all the images for the user, create a AWSS3 Pre signed URL and add this URL as a OLAsset assetWithURL : url

All is fine apart from at checkout when completing an order I get the error message "Oops! Only registered 0/2 image URLs with the asset endpoint"

How to sort this out?

kkarayannis commented 7 years ago

Hi @BillyJohn3, There doesn't seem to be a problem with signed S3 URLs. Just make sure they don't expire by the time the order is submitted. If that's not the issue, any chance that you can share an example with me in order to figure out what the problem is?

Thanks

BillyJohn3 commented 7 years ago

Thanks for your speedy response! I'm hoping to get this app out in the next couple days. the images expire after 1hr so that isn't the issue. Here's the code I use to get the OLAssets:

You will see that we grab a list of object file paths from parse and filter out to jpeg and jpg objects. then we create a AWSS3 request for each object and then add it to an array of OLAssets 'allItems'

for (PFObject *item in objects) {

    if ([[item[@"full_file_path"] lowercaseString] hasSuffix:@"jpeg"] || [[item[@"full_file_path"] lowercaseString] hasSuffix:@"jpg"]) {

        AWSS3GetPreSignedURLRequest *getPreSignedURLRequest = [AWSS3GetPreSignedURLRequest new];
        getPreSignedURLRequest.bucket = kUKAWSBucket;
        getPreSignedURLRequest.key = item[@"full_file_path"];
        getPreSignedURLRequest.HTTPMethod = AWSHTTPMethodGET;
        getPreSignedURLRequest.expires = [NSDate dateWithTimeIntervalSinceNow:3600];//was 3600
        getPreSignedURLRequest.contentType = @"image/jpeg";

        AWSS3PreSignedURLBuilder *builder = [AWSS3PreSignedURLBuilder S3PreSignedURLBuilderForKey:kAWSURLBuilderKey];
        [[builder getPreSignedURL:getPreSignedURLRequest] continueWithBlock:^id(AWSTask *task) {
            if (task.error) {
                NSLog(@"Error: %@", task.error);
            } else {
                [NSMutableURLRequest requestWithURL:task.result];
                NSURL *theURL = task.result;

                asset = [OLAsset assetWithURL:theURL];

                [allItems addObject:asset];
            }
            return nil;
        }];
    }
    else {
        NSLog(@"Item is not jpeg");
    }
}
kkarayannis commented 7 years ago

Your code seems fine, and if you can see the assets on the product previews you have probably done everything correctly. I will continue looking into this issue. In the meantime, can you confirm that you are using the latest version of the Kite SDK, currently v6.5.3? Also please let me know which product you are using to test the order submission.

In the meantime, what you can do is use [OLAsset assetWithDataSource:] and pass it any object that conforms to the OLAssetDataSource protocol. Doing this allows you to handle the downloading of the assets on your end.

BillyJohn3 commented 7 years ago

Yes, everything is up to date. And I've tried on photobooks and invitations. I re-wrote my code to make each url into an [OLAsset assetWithDataSource:] but this takes a really long time if the user has >100 photos. I have a HUD showing the user what's going on but it's still really unideal.

Have you managed to replicate the issue?

Cheers,

kkarayannis commented 7 years ago

Hi, Sorry for the late reply. I still can't replicate your issue. If you have some time, can you set a breakpoint on this line: https://github.com/OceanLabs/iOS-Print-SDK/blob/master/Kite-SDK/PSPrintSDK/OLAssetUploadRequest.m#L126 and see what the values for json and what the error is, if any?