crapthings edited a comment on issue #377: cordova-plugin file works on simulator but not real device? URL: https://github.com/apache/cordova-plugin-file/issues/377#issuecomment-586597907 hi, i've got problem solved by copy file to app group container you can't access /var/mobile/media maybe ? i make this plugin works like android, some work are copied from cordova-plugin-openwith https://github.com/crapthings/cordova-plugin-ios-shareextension android https://github.com/j3k0/cordova-plugin-openwith this is client code ```js import axios from 'axios' const fileReaderSync = file => new Promise(resolve => { const reader = new FileReader() reader.onloadend = function () { var blob = new Blob([new Uint8Array(this.result)], { type: file.type }) resolve(blob) } reader.readAsArrayBuffer(file) }) const resolveLocalFileSystemURLSync = uri => new Promise(resolve => { window.resolveLocalFileSystemURL(uri, function (fileEntry) { fileEntry.file(resolve) }) }) const uploadFiles = async function (urls) { const data = new FormData() if (urls.length > 0) { for (const item of urls) { const file = await resolveLocalFileSystemURLSync(item) const blob = await fileReaderSync(file) data.append('files', blob) } axios({ method: 'post', url: 'http://192.168.50.76:3000/api/upload', data, headers: {'Content-Type': 'multipart/form-data' } }) .then(function (response) { alert(JSON.stringify(response, null, 2)); }) .catch(function (response) { alert(response); }) } } Meteor.isCordova && Meteor.startup(function () { cordova.shareextension && cordova.shareextension.onFiles(async function (urls) { uploadFiles(urls) }, console.log) cordova.openwith && cordova.openwith.init && cordova.openwith.init(function () { cordova.openwith.addHandler(async function (intent) { const urls = _.map(intent.items, 'uri') uploadFiles(urls) }) }, console.log) }) ``` this is server code ```js import fs from 'fs' import express from 'express' import cors from 'cors' import bodyParser from 'body-parser' import multer from 'multer' const server = express() const router = express.Router() const UPLOAD_PATH = process.env.UPLOAD_PATH || '/Users/monsterstep/dev/cordova-playground/openwith/.uploads' const storage = multer.diskStorage({ destination: function (req, file, callback) { callback(null, UPLOAD_PATH) }, filename: function (req, file, callback) { file._id = Random.id() file.createdAt = new Date() callback(null, file._id) }, }) const uploader = multer({ storage }) server.use(cors()) server.use(bodyParser.json()) server.use(bodyParser.urlencoded({ extended: true })) server.use('/api', router) registerUploadRouter({ router }) WebApp.connectHandlers.use(Meteor.bindEnvironment(server)) function registerUploadRouter ({ router }) { router.post('/upload', uploader.array('files'), async function (req, res) { res.json(req.files) }) } ```
---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
