New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cordova build iOS fails #297
Comments
Which version are you installing? The current git master or the latest npm release? The latter does not work with cordova-ios@6 yet. |
@timbru31 It looks like they are using the npm released version. The supplied printout of the If they were using the git's main branch, it should show I guess they can try the git repo version, since the npm release does not work with |
I scrolled too fast through the list and missed the plugins section. Yes, the master works and we don't have an ETA for npm releases. |
Sorry, I got lost. How do I install the plug-in then without error on build?
…On Mon, 4 Jan 2021, 11:27 Tim Brust, ***@***.***> wrote:
Closed #297
<#297>.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#297 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA6M4DPXM7IAXDH25FNNBRDSYGJZXANCNFSM4VSXE3AQ>
.
|
|
Thanks a lot. Just one more further tiny question :)
I read your blog post wherein you refer this plugin is due to be deprecated
(you use the word "sunsetting") because now we can do the same with pure
javascript.
I just use this plugin to upload a file.
Can you tell the corresponding javascript code for the method ft.upload?
Thanks a lot in advance
…On Mon, 4 Jan 2021, 13:32 Tim Brust, ***@***.***> wrote:
cordova plugin add
https://github.com/apache/cordova-plugin-file-transfer.git#master
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#297 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA6M4DJJI32N3LQ7TWCPPTLSYGYMTANCNFSM4VSXE3AQ>
.
|
This plugin was deprecated (and there hasn't been a release to "undeprecate" it yet), but it was voted to bring it back because pure JS solutions still has some flaws in regards to efficiently working with large files.
You can read the file as a blob using the function readBinaryFile(fileEntry) {
fileEntry.file(function (file) {
var reader = new FileReader();
reader.onloadend = function() {
var blob = new Blob([new Uint8Array(this.result)], { type: "application/octet-stream" });
};
reader.readAsArrayBuffer(file);
}, onErrorReadFile);
} Once you have your blob object, you can upload using var xhr = new XMLHttpRequest();
xhr.open('POST', 'example.com/upload');
xhr.setRequestRequestHeader('Content-Type', theFileMimeType);
xhr.onload = function() {
// finished uploading (or error)... check xhr.status to be sure.
};
xhr.send(blob);
|
Thanks, I'm here for around 2 days to try to figure out exactly on how to upload a file in cordova using pure javascript. Please DO NOT deprecate this plugin because that's exactly the purposes of plugins and npm packages, to ease other people's work avoiding extra burden with something that someone had already developed. One single line which would suffice to upload a simple file with the help of this plugin, is becoming extremely cumbersome. That's what i got by now, but still with no success. I can't figure out the exact function which emulates function uploadFileToServer (fileUri, fileName, remoteUrl, callback) {
window.resolveLocalFileSystemURL(fileUri, function (fileEntry) {
fileEntry.file(function (file) {
var reader = new FileReader()
reader.onloadend = function () {
console.log('this.result', this.result)
var blob = new Blob([new Uint8Array(this.result)], { type: 'application/octet-stream' })
console.log('blob', blob)
var fd = new FormData()
fd.append('blob', blob, fileName)
var xhr = new XMLHttpRequest()
xhr.open('POST', remoteUrl)
xhr.setRequestHeader('Content-Type', 'multipart/form-data')
xhr.onload = function () {
if (xhr.status === 200) {
console.success(`File ${fileUri} uploaded succesfully to url ${remoteUrl}`)
if (typeof callback === 'function') { callback() }
} else {
console.error(`Error uploading file ${fileUri} to server`)
console.error(xhr.status)
if (typeof callback === 'function') { callback(xhr.status) }
}
}
xhr.onerror = function (err) {
console.error(`Error uploading file ${fileUri} to server`)
console.error(err)
if (typeof callback === 'function') { callback(err) }
}
xhr.send(fd)
}
console.log('file', file)
reader.readAsArrayBuffer(file)
}, function (err) {
console.error(`Error uploading file ${fileUri} to server`)
console.error(err)
if (typeof callback === 'function') { callback(err) }
})
})
} On the server side I use this: https://attacomsian.com/blog/uploading-files-nodejs-express I don't want steal your time, but can you see what am I missing? |
just to share my results, here a working pure JS function equivalent to function uploadFileToServer (fileUri, fileName, remoteUrl, callback) {
window.resolveLocalFileSystemURL(fileUri, function (fileEntry) {
fileEntry.file(function (file) {
var reader = new FileReader()
reader.onloadend = function () {
var blob = new Blob([new Uint8Array(this.result)], { type: 'application/octet-stream' })
var fd = new FormData()
fd.append('file', blob, fileName)
var xhr = new XMLHttpRequest()
xhr.open('POST', remoteUrl, true)
xhr.onload = function () {
if (xhr.status === 200) {
console.log(`File ${fileUri} uploaded succesfully to url ${remoteUrl}`)
if (typeof callback === 'function') { callback() }
} else {
console.error(`Error uploading file ${fileUri}. Server returned ${xhr.status}`)
if (typeof callback === 'function') { callback(xhr.status) }
}
}
xhr.onerror = function (err) {
console.error(`Error uploading file ${fileUri} to server`)
console.error(err)
if (typeof callback === 'function') { callback(err) }
}
xhr.send(fd)
}
reader.readAsArrayBuffer(file)
}, function (err) {
console.error(`Error uploading file ${fileUri} to server`)
console.error(err)
if (typeof callback === 'function') { callback(err) }
})
})
} |
I made a gist on the subject if you're interested Thanks |
Good day! I have the same problem. Help please. What can I do? Use ios: 6.1.1 Build failed. The following build commands failed: |
Hi @klochko7 |
Hi, jfoclpf. I am using 2.0.0-dev. It dose not build. Am I right ? |
according to @timbru31 it should work. I just use now pure javascript. Just copy the functions and it works. |
Hi @jfoclpf |
BTW, @klochko7 did you remove the old plugin version?
|
I will try. Thank you very much. |
Bug Report
Problem
What is expected to happen?
the build of iOS via
cordova build ios
should work correctlyWhat does actually happen?
it throws an error
when I remove this plugin the build succeeds
Information
Command or Code
cordova build ios
Environment, Platform, Device
iOS
Version information
macOS, standard cordova
Checklist
The text was updated successfully, but these errors were encountered: