question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

File upload fails: is not valid file

See original GitHub issue

Uploading fails with “Application error: Error /Users/user/Library/Developer/CoreSimulator/Devices/11C75134-AC52-46B8-87F6-58A61B8A1E0C/data/Containers/Data/Applicatio … 282.jpeg is not a valid file:// url undefined” on iOS emulator. The path is correct and a valid image can be found at this path.

tns-core-modules: 1.7.1 tns-ios : 2.0.0 tns-android: 2.0.0 nativescript-background-http: 0.0.3

The code snippet:

import cameraModule = require('camera')
import imageModule  = require('ui/image')
import enumsModule  = require('ui/enums')
import fsModule     = require('file-system')
import bgHttpModule = require('nativescript-background-http')

const options = { width: 300, height: 300, keepAspectRatio: true }
const format = enumsModule.ImageFormat.jpeg

cameraModule.takePicture(options).then(imageSource => {
    let contentType = `image/${format}` 
    let base64String = imageSource.toBase64String(format)
    let savePath = fsModule.knownFolders.documents().path
    let fileName = 'img_' + new Date().getTime() + '.' + format
    let filePath = fsModule.path.join( savePath, fileName )

    if ( imageSource.saveToFile( filePath, format ) ) {
        var session = bgHttpModule.session('image-upload')

        var options = {
            url: 'http://192.168.99.100:8003',
            method: 'POST',
            headers: {
                'Content-Type': 'application/octet-stream',
                'File-Name': fileName
            },
            description: '{ \'uploading\': ' + fileName + ' }'
        }

        let task = session.uploadFile(filePath, options)

        task.on('progress', logEvent)
        task.on('error', logEvent)
        task.on('complete', logEvent)

        function logEvent(e) {
            console.log(e.eventName)
        }
    }
})

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
NickIlievcommented, Sep 15, 2016

@roblav96 yes this is resolved with this commit

0reactions
dlucidonecommented, May 11, 2017

the error eim getting is with the name being sent as whole path. I edited in the plugin and made a pull request in the repo

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: File upload failed. (file name) Invalid File Name
Answer: · Ensure you are logged into the Files Folder and are in the folder in which to upload the file. · In...
Read more >
Uploaded file is not valid for copy... - DirectAdmin Forums
Whenever I upload an image through DA it says: Uploaded file is not valid for copy. When checking something deeper into the error...
Read more >
No longer able to upload files due to error message
When uploading files to an existing SharePoint folder, receive the following message 'The URL <file name> is invalid.
Read more >
File upload form not valid - django - Stack Overflow
The form loads fine and I can upload a file but after 'submit' I can not get past Fileform. is_valid() in the view....
Read more >
Error message on upload: "No file uploaded or invalid file type!"
Error message on upload: "No file uploaded or invalid file type!" ... This message has two common causes: ... PKP software uses MIME...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found