zwwcn

Just another WordPress.com site

Monthly Archives: January 2016

Set Content Security Policy for Cordova app

I’m getting some error when debuging my cordova app on Android device.  The error msg is

Refused to load the image 'data:image/png;base64,....' because it violates the following Content Security Policy directive: "img-src 'self' data".

I googled it and found that I need to set content security policy meta tag.

This link gives detailed example and helped me solve the problem.

MySQL innodb file too large

We had problem when altering one of our largest table in MySQL server. Eventually we managed to apply the change, but MySQL wouldn’t release the disk space it took for temp table. MySQL mark the data as deleted, but it still holding the space. This link gives good answer on this problem:

Optimize innodb table when innodb_file_per_table disable

Read photo taken date from image

For Java, I use metadata-extractor:

Metadata metadata = ImageMetadataReader.readMetadata( item.getInputStream());
ExifSubIFDDirectory directory = metadata.getFirstDirectoryOfType(ExifSubIFDDirectory.class);
Date date = directory.getDate(ExifSubIFDDirectory.TAG_DATETIME_ORIGINAL);
if(date != null){
    file.setPhotoTakenDate(date);
}

For front end, I use exif-js:

window.resolveLocalFileSystemURL(attachmentInfo.fileSource, (fileEntry) ->
                fileEntry.file((file) ->
                    EXIF.getData(file, ->
                    	
                        galleryPhotoTakenDate = EXIF.getTag(this,"DateTimeOriginal");
                      
                        cameraPhotoTakenDate = this.lastModifiedDate;

                        if photoFromCamera
                            if typeof cameraPhotoTakenDate != 'undefined'
                                #photo taken from camera
                                attachmentInfo.photoTakenDate = moment(cameraPhotoTakenDate).format("YYYY:MM:DD HH:mm:SS")
                        else
                            if typeof galleryPhotoTakenDate != 'undefined'
                                #photo taken from gallery
                                attachmentInfo.photoTakenDate = galleryPhotoTakenDate 
                            
                    )                    
                )
                    
            )