save picture to album in CORDOVA


CDVCamera.m 에서

writeImageDataToSavedPhotosAlbum:self.data

2020-06-03 07:57:36.221393+0900[3602:1883425] Apache Cordova native platform version 5.0.1 is starting.
2020-06-03 07:57:36.221469+0900[3602:1883425] Multi-tasking -> Device: YES, App: YES
2020-06-03 07:57:36.231134+0900[3602:1883425] *** Assertion failure in -[CDVConfigParser parser:parseErrorOccurred:], /Users/soralee/Documents/GitHub/DaelimOCR/CordovaLib/Classes/Public/CDVConfigParser.m:78

NSData *imgdata = [[NSData alloc]initWithBase64EncodedString:base64Image options:NSDataBase64DecodingIgnoreUnknownCharacters];

                                                  ALAssetsLibrary *library = [ALAssetsLibrary new];

                                                        [library writeImageDataToSavedPhotosAlbum:imgdata metadata:nil completionBlock:nil];

                                  }

                }

NSURL *bundleURL = [[NSBundle mainBundle] URLForResource:@"CDVCamera" withExtension:@"bundle"];

    NSBundle *bundle = [NSBundle bundleWithURL:bundleURL];

    NSString *imagePath = [bundle pathForResource:@"cameraguide" ofType:@"png"];

    UIImage *uandImage = [UIImage imageWithContentsOfFile:imagePath];

//    UIImage *uandImage =  [UIImage imageNamed:@"cameraguide.png"];

주석 처리된 것은 deply 된 프로젝트에서 쓰고 그 위의 코드들은 bundle directory를 만든 경우 쓴다.

 

 

 

1. Camera.js takePicture2 호출하는 getPicture2 삽입

 

cameraExport.getPicture2 = function (successCallback, errorCallback, options) {

        argscheck.checkArgs('fFO', 'Camera.getPicture', arguments);

        options = options || {};

        var getValue = argscheck.getValue;

 

        var quality = getValue(options.quality, 50);

        var destinationType = getValue(options.destinationType, Camera.DestinationType.FILE_URI);

        var sourceType = getValue(options.sourceType, Camera.PictureSourceType.CAMERA);

        var targetWidth = getValue(options.targetWidth, -1);

        var targetHeight = getValue(options.targetHeight, -1);

        var encodingType = getValue(options.encodingType, Camera.EncodingType.JPEG);

        var mediaType = getValue(options.mediaType, Camera.MediaType.PICTURE);

        var allowEdit = !!options.allowEdit;

        var correctOrientation = !!options.correctOrientation;

        var saveToPhotoAlbum = !!options.saveToPhotoAlbum;

        var popoverOptions = getValue(options.popoverOptions, null);

        var cameraDirection = getValue(options.cameraDirection, Camera.Direction.BACK);

 

        var args = [quality, destinationType, sourceType, targetWidth, targetHeight, encodingType,

            mediaType, allowEdit, correctOrientation, saveToPhotoAlbum, popoverOptions, cameraDirection];

 

        exec(successCallback, errorCallback, 'Camera', 'takePicture2', args);

        // XXX: commented out

        // return new CameraPopoverHandle();

    };

 

2. selvyOcrPlugin.js

navigator.camera.getPicture2(

        // 성공 콜백 함수

카메라 호출 함수 getPicture2 변경

 

3. CDVCamera.h/.m 수정하여 가이드 삽입



이 정도 작업들을 하였다. 급변하는 요구 사항에 빠른 대응은 2, 3, 4 로 이어지는 의미 없는 네이밍. 네이밍에 개발 시간 50% 이상을 쓴다. ㅡㅡ; 물론, 나 혼자 아키텍팅하고 개발하는 프로젝트는 네이밍에 더 신경을 써야지

 

const express = require('express')

const siofu = require("socketio-file-upload")

const app = express()

const path = require('path')

const http = require('http').Server(app)

const io = require('socket.io')(http)

const parseTorrent = require('parse-torrent')

const torrentStream = require('torrent-stream')

const zipFolder = require('zip-folder')

const numeral = require('numeral')

const uniqId = function () {

  return Math.round(new Date().getTime() + (Math.random() * 100))

}

const rmdir = require('rimraf')

const fs = require('fs')

const bytes = function(num) {

  return numeral(num).format('0.0b');

}

const simples = function(num) {

  return numeral(num).format('0');

}

 

 

app.use("/static", express.static('public'))

 

app.set('view engine', 'pug')

 

app.get('/', (request, response) =>{

  rmdir('public/files/', function(error){});

  response.render('layouts/app', { title: 'TorrentSpeak'})

})

 

io.on('connection', function(socket){

  let uploader = new siofu()

  uploader.dir = "upload/"

  uploader.listen(socket)

  // Do something when a file is saved:

  uploader.on("saved", function(event){

      torrentFile = event.file.pathName

      var msg = parseTorrent(fs.readFileSync(torrentFile))

      parseTorrent.remote(msg, function (err) {

 

        if (err) {

          io.emit('error dl')

        }

        else{

          io.emit('add torrent')

          let id = uniqId()

          let engine = torrentStream(msg,{

              'connections': 100,

              'path': './public/files/'+id

          })

          engine.on('ready', function() {

              engine.files.forEach(function(file) {

                  file.select()

              })

          })

          engine.on('download', function(){

            downloadLength = engine.swarm.downloaded

            totalLength = engine.files.reduce(function (prevLength, currFile) {return prevLength + currFile.length}, 0);

            var draw = simples(downloadLength* 100 / totalLength)

            var progress = bytes(downloadLength)+'/'+bytes(totalLength)

            io.emit('edit dl', progress, draw)

          })

          engine.on('idle', function(){

            zipFolder('./public/files/'+id, './public/files/'+id+'.zip', function(err) {

                if(err) {

                } else {

                    io.emit('end dl', './static/files/'+id+'.zip')

                }

            })

            engine.destroy()

          })

        }

      })

      fs.unlink(torrentFile)

  });

  // Error handler:

  uploader.on("error", function(event){

      io.emit('error dl')

      console.log("Error from uploader", event);

  });

  socket.on('add magnet', function(msg){

 

    parseTorrent.remote(msg, function (err) {

 

      if (err) {

        io.emit('error dl')

      }

      else{

        io.emit('add magnet', msg)

        let id = uniqId()

        let engine = torrentStream(msg,{

            'connections': 100,

            'path': './public/files/'+id

        })

        engine.on('ready', function() {

            engine.files.forEach(function(file) {

                file.select()

            })

        })

        engine.on('download', function(){

          downloadLength = engine.swarm.downloaded

          totalLength = engine.files.reduce(function (prevLength, currFile) {return prevLength + currFile.length}, 0);

          var draw = simples(downloadLength* 100 / totalLength)

          var progress = bytes(downloadLength)+'/'+bytes(totalLength)

          io.emit('edit dl', progress, draw)

        })

        engine.on('idle', function(){

          zipFolder('./public/files/'+id, './public/files/'+id+'.zip', function(err) {

              if(err) {

              } else {

                  io.emit('end dl', './static/files/'+id+'.zip')

              }

          })

          engine.destroy()

        })

      }

 

    })

 

 

  })

 

  socket.on('disconnect', function(){

  })

})

 

http.listen(5555, function(){})

비트토렌트 스트리밍 모듈이 node.js 에 있었네.

 

새로운 세상.

 

'Blog History' 카테고리의 다른 글

414  (0) 2020.06.04
413  (0) 2020.06.03
411  (0) 2020.06.03
410  (0) 2020.06.03
409  (0) 2020.06.03

+ Recent posts