Size of taken picture from camera


#1

Hi guys,
my app take a picture and then try to upload to S3.

I use the File Transfer plugin, and I need to set ‘Content-Length’ to the array header.

I do:

let options: FileUploadOptions = {
           fileKey: 'file',
           fileName: 'name.jpg',
           mimeType: "image/jpeg",
           httpMethod: "PUT",
           chunkedMode: false,
           headers: {
            "Content-Type": 'image/jpeg',
            'Content-length' : ????
          },
       
        }
        
        fileTransfer.upload(this.imagePath, url.url, options)
         .then((data) => {
           // success
           console.log("success: " , data);
         }, (err) => {
           // error
           console.log("error upload:", JSON.stringify(err, null, 4));
         })

this.imagePath is the path of the taken picture from camera, it’s like this:

file:///storage/emulated/0/Android/data/it.oandsi.photoshoot.com/cache/1522925072046-cropped.jpg?1522925073891

I have only the path because in configuration of the camera I specified:

destinationType: this.camera.DestinationType.FILE_URI,

How to get the length of the picture?

Thanks!


#2

I also facing the problem with video and images upload to the server


#3

You both can have a look at this…
https://devdactic.com/ionic-image-upload-app/


#4

maybe I didn’t explain good my issue. Your link doesn’t show me how to retrieve the size of taken picture.
My issue is: I take a picture, then I have its path, now I want get the size (length of bytes)


#5

Hi, @gjord

You have to use DOM properties get image actual dimensions.

Try this:

<img id="imageid" src="file:///storage/emulated/0/Android/data/it.oandsi.photoshoot.com/cache/1522925072046-cropped.jpg?1522925073891">

var img = document.getElementById('imageid'); 

var width = img.clientWidth; // For width
var height = img.clientHeight; // For height

Thank you.


#6

I thanks to you, but my question is about size (lenght, bytes…), not about CSS property :frowning:


#7

Have you tried the technique described here? Incidentally, the file-transfer plugin is obsolete and should not be used in new code.


#8

and what I have to use?