Nativescript: how to compress images before upload in NS

Created on 26 May 2017  Â·  8Comments  Â·  Source: NativeScript/NativeScript

the photo is more than 4M,i want to compress before upload,how to do?

question

All 8 comments

compress the ImageAsset or the ImageSource

Can you clarify what you mean with "before uploading in NS"?
If you are creating large images on the user device (e.g. using Camera) then you can control the size of the image. Or you can send the image as a base64 string. If you want to control the image size on download (e.g. when using some online API and the src property) then you can downsample the images with using decodeWidth and decodeHeight for Android (article here).

As a side note, I would suggest to post similar questions in the community channels like forum.nativescript.org and SO where you can receive faster answers from the community members and in the same time we can keep this repo clean for issues, bugs and feature related threads.

i select the photo form the album,the photo is more then 3M。i use the nativescript-background-http upload, it's slowly。so i want to compress the selected photos。

similar to the https://github.com/NativeScript/NativeScript/issues/3605

@giscafer you can use the converting to base64 technique decided in the linked issue via ImageSource module and the method _toBase64String_

e.g.based on this sample application

import { fromFileOrResource } from "image-source";

let img = fromFileOrResource("~/images/cosmos.jpg");
let baseString = img.toBase64String("jpeg");

console.log(baseString);

Currently, there are no compression plugins for NativeScript, but I would also recommend joining and posting your question in the community channels and especially the forum.nativescript.org where the communiti is very active and other possible solutions can be provided.

did you guess got any plugin to compress image in nativescript angular ?

no,it's so sad I have to say

@himank1991 @pospospos2007 the method toBase64String also has a quality parameter which can be used to compress large images. See this thread for details.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

NickIliev picture NickIliev  Â·  3Comments

guillaume-roy picture guillaume-roy  Â·  3Comments

nirsalon picture nirsalon  Â·  3Comments

rLoka picture rLoka  Â·  3Comments

vtisnado picture vtisnado  Â·  3Comments