DropZone parallelUploads not working I have set parallelUploads to 10 but it is uploading 20 in one request - dropzone

I have DropZone to upload files.
I have set parallelUploads to 10. I am dropping 125 files and I am getting just one request to server and there are 20 files in one request. I have also set parallelUploads to 9999 but again just 20 files I receive on server.
Here is the code:
Dropzone.autoDiscover = false;
//maxFilesize: 20 is 20 MB
var myDropzone = new Dropzone("#myDropzoneForm", {
addRemoveLinks: true,
method: 'post',
uploadMultiple: true,
parallelUploads: 10, // Also set to 9999 but not working
maxFileSize: 4,
autoProcessQueue: false
});
myDropzone.on('addedfiles', function () {
setTimeout(function () {
sendFiles();
}, 1);
});
myDropzone.on('addedfile', function (file) {
var iFilesLength = myDropzone.files.length;
if (iFilesLength > 0) {
var bFileFound = false;
for (var iiFileLength = iFilesLength - 1; iiFileLength >= 0; iiFileLength--) {
if (file.name == myDropzone.files[iiFileLength].name) {
if (bFileFound)
myDropzone.removeFile(myDropzone.files[iiFileLength]);
else bFileFound = true;
}
}
}
});
function sendFiles() {
if (myDropzone.files.length > 0) {
myDropzone.processFiles(myDropzone.files);
}
}
myDropzone.on('successmultiple', function (file, responseText) {
$("#myResponse").html(responseText);
});

It was an issue of php.ini. As we know there are default configuration settings set in php.ini. In this file default value is max_file_uploads = 20 so change this to max_file_uploads = 99999.
Refresh your server and see it will work.
And problem solved.

Related

MediaRecorder Blob to file in an electron app

I have an electron app that has very simple desktop capturing functionality:
const {desktopCapturer} = require('electron')
const fs = require('fs');
var recorder;
var chunks = [];
var WINDOW_TITLE = "App Title";
function startRecording() {
desktopCapturer.getSources({ types: ['window', 'screen'] }, function(error, sources) {
if (error) throw error;
for (let i = 0; i < sources.length; i++) {
let src = sources[i];
if (src.name === WINDOW_TITLE) {
navigator.webkitGetUserMedia({
audio: false,
video: {
mandatory: {
chromeMediaSource: 'desktop',
chromeMediaSourceId: src.id,
minWidth: 800,
maxWidth: 1280,
minHeight: 600,
maxHeight: 720
}
}
}, handleStream, handleUserMediaError);
return;
}
}
});
}
function handleStream(stream) {
recorder = new MediaRecorder(stream);
chunks = [];
recorder.ondataavailable = function(event) {
chunks.push(event.data);
};
recorder.start();
}
function stopRecording() {
recorder.stop();
toArrayBuffer(new Blob(chunks, {type: 'video/webm'}), function(ab) {
var buffer = toBuffer(ab);
var file = `./test.webm`;
fs.writeFile(file, buffer, function(err) {
if (err) {
console.error('Failed to save video ' + err);
} else {
console.log('Saved video: ' + file);
}
});
});
}
function handleUserMediaError(e) {
console.error('handleUserMediaError', e);
}
function toArrayBuffer(blob, cb) {
let fileReader = new FileReader();
fileReader.onload = function() {
let arrayBuffer = this.result;
cb(arrayBuffer);
};
fileReader.readAsArrayBuffer(blob);
}
function toBuffer(ab) {
let buffer = new Buffer(ab.byteLength);
let arr = new Uint8Array(ab);
for (let i = 0; i < arr.byteLength; i++) {
buffer[i] = arr[i];
}
return buffer;
}
// Record for 3.5 seconds and save to disk
startRecording();
setTimeout(function() { stopRecording() }, 3500);
I know that to save the MediaRecorder blob sources, I need to read it into an ArrayBuffer, then copy that into a normal Buffer for the file to be saved.
However, where this seems to be failing for me is combining the chunk of blobs into blobs. When the chunks are added into a single Blob - it's like they just disappear. The new Blob is empty, and every other data structure they are copied into afterwards also is completely empty.
Before creating the Blob, I know I have valid Blob's in the chunks array.
Here's what the debug info of chunks is, before executing the new Blob(chunks, {.. part.
console.log(chunks)
Then here's the debug info of the new Blob(chunks, {type: 'video/webm'}) object.
console.log(ab)
I'm completely stumped. All the reference tutorials or other SO answers I can find basically follow this flow. What am I missing?
Electron version: 1.6.2
That's not possible to be working. You didn't wait for value to come in stopReocoring. You need to change your stopRecording function to following:
function stopRecording() {
var save = function() {
console.log(blobs);
toArrayBuffer(new Blob(blobs, {type: 'video/webm'}), function(ab) {
console.log(ab);
var buffer = toBuffer(ab);
var file = `./videos/example.webm`;
fs.writeFile(file, buffer, function(err) {
if (err) {
console.error('Failed to save video ' + err);
} else {
console.log('Saved video: ' + file);
}
});
});
};
recorder.onstop = save;
recorder.stop();
}
This problem literally just fixed itself today without me changing anything. I'm not sure what about my system changed (other than a reboot) but it's now working exactly as it should.

Multi part form-data image upload using cordova-file-transfer plugin in ios fails

I have to upload an image to server using multi-part image upload from my ionic project. Here is my code,
$scope.uploadImage = function(imageUrl) {
var fileName = imageUrl.substring(imageUrl.lastIndexOf('/')+1);
var json= {
"id":123,
"name" :fileName
}
var fileUploadOptions = new FileUploadOptions();
fileUploadOptions.fileKey="file";
fileUploadOptions.fileName = fileName;
fileUploadOptions.params = {
json : json
};
fileUploadOptions.mimeType="image/jpeg";
var URL = 'http://192.168.43.7:8080/services/uploadImage'
var encodedURI = encodeURI(URL);
console.log('fileUploadOptions : ',fileUploadOptions);
var ft = new FileTransfer();
ft.upload(imageUrl, encodedURI, onSuccess, onError, fileUploadOptions, false);
function onSuccess(response){
console.log('file uploaded: ',response);
}
function onError(error){
console.log('upload failed',error);
}
}
I am using the following plugins
cordova-plugin-file
cordova-plugin-file-transfer
cordova-plugin-camera
My image capture code is
$scope.takePhoto = function() {
var options = {
quality: 75,
destinationType: Camera.DestinationType.FILE_URI,
sourceType: 1,
allowEdit: false,
encodingType: 0,
targetWidth: 1280,
targetHeight: 720,
popoverOptions: CameraPopoverOptions,
direction: 1,
saveToPhotoAlbum: true
};
var cameraSuccess = function(imageData) {
onPhotoURISuccess(imageData);
function onPhotoURISuccess(imageURI) {
createFileEntry(imageURI);
}
function createFileEntry(imageURI) {
window.resolveLocalFileSystemURL(imageURI, copyPhoto, fail);
}
function copyPhoto(fileEntry) {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSys) {
fileSys.root.getDirectory("photos", { create: true, exclusive: false }, function(dir) {
var fileName = 12 + "_" + 56 + "_" + 67 + ".jpg";
fileEntry.copyTo(dir, fileName, onCopySuccess, fail);
}, fail);
}, fail);
}
function onCopySuccess(entry) {
console.log('Full path: ', JSON.stringify(entry));
var path = entry.toURL();
$scope.imageUrl = path;
console.log('imageUrl: ',$scope.imageUrl);
}
function fail(error) {
console.error(JSON.stringify(error));
var cause = "";
if (error.code == 20) {
cause = "Camera permission denied"
}
}
}
var cameraError = function(error) {
console.log('camera error: ', error);
}
navigator.camera.getPicture(cameraSuccess, cameraError, options);
}
I am passing the $scope.imageUrl variable to upload function.
The code works fine in android devices.
But iOS, the upload fails.
I am getting
com.fasterxml.jackson.databind.JsonMappingException: No content to map due to end-of-input
error in my server console.
In my device console I am getting the following error,
upload failed
body: "An error has occurred. Please contact system administrator."
code: 3
exception: null
http_status: 500
source: "file:///var/mobile/Containers/Data/Application/8C4518AC-5606-4806-A8D2-216125EFE725/Documents/photos/12_56_57.jpg"
target: "http://192.168.43.7:8080/services/uploadImage"
The message in the body of the error is from my server.
As per the error I get from server, I came to know that, the JSON part is not getting uploaded to server. I tried to recreate the same issue with postman without sending the JSON object. I got the same error.
Do anyone know what is the issue ? Why only in iOS device this issue is there ?
From the docs:
params: A set of optional key/value pairs to pass in the HTTP request. (Object, key/value - DOMString)
Try using fileUploadOptions.params = { json : JSON.stringify(json) } instead.
var imageUrI="file:///storage/emulated/0/newfile.csv";
var options = new FileUploadOptions();
options.fileKey = "file";
options.fileName = imageURI.substr(imageURI.lastIndexOf('/') + 1);
options.mimeType = "image/jpeg/csv";
var params = new Object();
params.value1 = "test";
params.value2 = "param";
options.params = params;
options.chunkedMode = false;
var ft = new FileTransfer();
ft.upload(imageURI, "http://fileupload/admin/add_image_my.php",
function (result) {
console.log(JSON.stringify(result));
},
function (error) {
console.log(JSON.stringify(error));
}, options);

Javascript: Stop running interval in background

I am creating an extension for Firefox. This includes using self.port. Here's my code in panel.js:
self.port.on("showDlg", function(val) {
document.getElementById('queen').onclick = function(){
self.port.emit("song", 'queen');
};
document.getElementById('beatles').onclick = function(){
self.port.emit("song", 'beatles');
};
});
Here's the content.js:
self.port.on("song", function(val) {
if (val.code = 'queen'){
interval = setInterval(function () {
console.log('show must go on');
}, 1000);
} else if (val.code == 'beatles'){
interval = setInterval(function () {
console.log('yesterday');
}, 1000);
}
}
It is all working, when I click queen, it prints me show must go on every 1 second. But when I click beatles, it still prints show must go on along with yesterday.
How can I stop previous interval? As far as I understand, it runs in the background, and every action is a new instance. If so, how can I stop previous instance?
Thanks.
self.port.on("song", function(val) {
self.interval && clearInterval(self.interval);
self.interval = null;
if (val.code = 'queen'){
self.interval = setInterval(function () {
console.log('show must go on');
}, 1000);
} else if (val.code == 'beatles'){
self.interval = setInterval(function () {
console.log('yesterday');
}, 1000);
}
}

bootstrap min. js is running the request 2 times and hang until not refresh the page

[my ajax]
when i run the code the bootstrap.min.js will run but there two isssues comes in that 1. that is hit the request two time and 2. that after the 2 hit it will have to close the popup and hang the page until it refresh the page
function add_edit_party(){
var place_id = myFunction();
var $j = jQuery.noConflict();
var estimated_wait = 0;
var no_sms = "";
var is_hd = 0;
$j('.alert-danger').removeClass('show').addClass('hide');
if($j('#'+place_id+'_wl_phone').val()){
phone_length = $j('#'+place_id+'_wl_phone').val().length;
if (phone_length!=10){
$j('#'+place_id+'_wl_phone').next().removeClass('hide').addClass('show');
return false;
}
}
if(!validateEmail($j('#'+place_id+'_wl_email').val())){
$j('#'+place_id+'_wl_email').next().removeClass('hide').addClass('show');
return false;
}
if($j('#'+place_id+'_wl_unknown_persons').val()==""){
$j('#'+place_id+'_wl_unknown_persons').next().removeClass('hide').addClass('show');
return false;
}
if($j('#'+place_id+'_wl_estimated_wait').val()=="" && $j('#serve_time').val() == "1"){
$j('#'+place_id+'_wl_estimated_wait').next().removeClass('hide').addClass('show');
return false;
}
if ($j('#serve_time').val() == "0"){
estimated_wait = 0;
}
if ($j('#serve_time').val() == "1")
estimated_wait = $j('#'+place_id+'_wl_estimated_wait').val();
}
place_party_req_id = "";
if($j('#place_party_req_id').val()){
place_party_req_id = $j('#place_party_req_id').val();
}
request_param = {
place_id : place_id,
color_update_at: "3",
name : $j('#'+place_id+'_wl_name').val(),
notes : $j('#'+place_id+'_wl_notes').val(),
phone : "0"+$j('#'+place_id+'_wl_phone').val(),
email : $j('#'+place_id+'_wl_email').val(),
unknown_persons : $j('#'+place_id+'_party_size').val(),
size : $j('#'+place_id+'_party_size').val(),
estimated_wait : estimated_wait,
color_status: 3,
party_request_id: place_party_req_id,
authenticity_token : window._token
};
$j(".loading").show();
var url='/add_party/'+place_id
$j.ajax({
type: "POST",
url: url,
async: false,
data: request_param,
dataType : 'json',
success: function(result){
if(result['party_id']){
if($j('#place_party_req_id').val()){
edit_party_request($j('#place_party_req_id').val(),'accepted');
$j('#place_party_req_id').val("");
}
party_id = result['party_id'];
if(estimated_wait=='0'){
seat_party(party_id);
return;
}
refresh_wl();
setTimeout(function(){ jQuery(".loading").hide(); }, 600);
$j('#myModal').modal('hide');
$j('.nav-tabs a:first').tab('show');
}
},
error: function(msg){
//alert("Something went wrong...");
}
});
return false;
}
see whether you have added multiple js files in your layout file.It may be application.js or jquery.js.Many a times we add js file in the view as well as in the layout as well...
Moreover there can be a chance where any custom js in application.js will also having a duplicate file already included in application.js file.Please check

Phonegap 3.5 File Download / Moving not working

I am busy upgrading a Phonegap app from 3.3 to 3.5 everything works so far but the file download, opening isn't working
function downloadFile(url, filename, fail, downloadDone) {
window.fail = fail;
window.downloadDone = downloadDone;
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function onFileSystemSuccess(
fileSystem) {
var fileTransfer = new FileTransfer();
fileTransfer.download(url, window.filePath + filename, function(theFile) {
window.downloadDone();
}, function(error) {
window.fail(error);
});
}, window.fail);
}
function setupFilePath(callBack) {
window.callback = callBack;
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function onFileSystemSuccess(
fileSystem) {
fileSystem.root.getFile("dummy.html", {
create: true,
exclusive: false
}, function gotFileEntry(fileEntry) {
var sPath = fileEntry.root.replace("dummy.html", "");
window.filePath = sPath;
var fileTransfer = new FileTransfer();
fileEntry.remove();
dataDir = fileSystem.root.getDirectory(sPath + 'cordapp', {
create: true
});
window.filePath = sPath + 'cordapp/';
console.log("FILE PATH IS: " + window.filePath)
callBack()
}, null);
}, null);
}
Getting the error that the app can't create the directory what am I doing wrong? Is there also a way to not letting it backup to iCloud?

Resources