Skip to content

It shows images from the library but gets an error when try to use them (iOS / not local images) #53

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ignaciolarranaga opened this issue Dec 12, 2016 · 1 comment

Comments

@ignaciolarranaga
Copy link
Contributor

Steps to reproduce:

When you try to use them (for example upload them) there is no fileUri then not usable.

Here is the log for example of one of them:

CONSOLE LOG file:///app/main-page.js:90:24: Total bytes to transfer: 0
CONSOLE LOG file:///app/main-page.js:83:20: ----------------
CONSOLE LOG file:///app/main-page.js:84:20: Status: complete
CONSOLE LOG file:///app/main-page.js:85:20: Error: undefined
CONSOLE LOG file:///app/tns_modules/nativescript-imagepicker/images.js:18:20: 736
CONSOLE LOG file:///app/tns_modules/nativescript-imagepicker/images.js:19:20: 736
CONSOLE LOG file:///app/tns_modules/nativescript-imagepicker/images.js:18:20: 736
CONSOLE
LOG file:///app/tns_modules/nativescript-imagepicker/images.js:19:20: 736
@ignaciolarranaga ignaciolarranaga changed the title It shows images from the library but gets an error when try to use them (iOS) It shows images from the library but gets an error when try to use them (iOS / not local images) Dec 12, 2016
@tsonevn
Copy link
Contributor

tsonevn commented Dec 14, 2016

Hi @ignaciolarranaga,
Thank you for reporting this issue.
I reviewed this case and indeed images from the cloud do not have fileUri and you should make one extra step. You could use getImage(), which will return imageSource. then you could save it on the device with saveToFile(<file_path>, <file_type>). As a result you will be able to use the saved image path to upload it with nativescript-background-http. I will review the sample-ImageUpload plugin and will make the needed changes. I am attaching sample code with the above-given suggestion.

var counter= 0;
function startSelection(context) {
	context
		.authorize()
		.then(function() {
            imageItems.length = 0;
			return context.present();
		})
		.then(function(selection) {
			selection.forEach(function(selected_item) {
                selected_item.getImage().then(function(imagesource){
                    let folder = fs.knownFolders.documents();
                    let path = fs.path.join(folder.path, "Test"+counter+".png");
                    let saved = imagesource.saveToFile(path, "png");
                    if(saved){
                        imageItems.push({thumb:imagesource});
                        var test = sendImages("", path);
                    }
                    counter++;
                })
                
			});
			//list.items = selection;
		}).catch(function (e) {
			console.log(e);
		});
}

Hope this will help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants