-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Programatically add files #211
Comments
Try this var dummy = new FileUploader.FileItem(uploader, {
lastModifiedDate: new Date(),
size: 1e6,
type: 'image/jpeg',
name: 'test_file_name'
});
dummy.progress = 100;
dummy.isUploaded = true;
dummy.isSuccess = true;
uploader.queue.push(dummy); |
Hi, If I use a url instead of file name for the "name" property, will it work? If not, do you have any suggestions for this? (The image is stored in the server) Thanks! |
For what purpose you want to change the name |
I mean... does the file have to be stored locally? Or could it be an image stored on a remote location and add it through specifying an url? |
Maybe I misunderstood your question, but a file upload is to recover a file from a PATH (remote or on the same machine) to another PATH The home directory can be retrieved with the angular-api file-upload and remote directory you can set it manually i dont knew if i have answered to your question or i m out ^^ |
mmmmm ok... may be I'm a bit confused. I will take a look later (I'm at work right now) and I let you know how it went. Thanks! |
Should this approach result in the file upload control displaying 'test_file_name'? When I use your sample code above, I see an item has been added to the uploader.queue array, but the UI doesn't show the file name. My goal is to pre-load the UI as it would look if the user clicked Choose File and uploaded "test_file_name".
Thanks! |
Hi guys! How to obtain FileItem from remote URL? I already tryed:
|
I have the same issue , with displaying remote files (uploaded before) after page reload. I tried, but unfortunately it is not working. var uploader.url = '/data/uploads/';
var fileItem = new FileUploader.FileItem(uploader, {
lastModifiedDate: new Date(),
type: 'image/jpeg',
size: 1311776,
name: 'logo.jpg'
});
fileItem.progress = 100;
fileItem.isUploaded = true;
fileItem.isSuccess = true;
uploader.queue.push(fileItem); |
This seemed to work for me (I'm using Angular): Get files via $http, my JSON snippet looks like so: "UploadedFiles": [ for(var i = 0; i < $scope.user.UploadedFiles.length; i++ ){
} Hope this helps :) |
But where to put actual file object ? I want to preview files which are already uploaded ? Can somebody help me with this ? |
+1 how to preview the uploaded image with url ? |
finally got it. hope this code can help someone var url = 'api/containers/comK/download/IMG_20130731_211048.jpg'; |
Hi TonyLuo, |
great plugin mate but when I add the dummy there is no event for added File. this screws up a litle my programming, I need a list of all the added files (including dummies) to edit other information in the files that will go into the database. |
also why is the fileItem index ALWAYS null? |
I have been trying to show the already uploaded files into the uploader queue but it is not displaying.
|
Put dummy FileItem inside get request, then it will work fine ... |
everything is fine but would also add to the image displayed ? |
I have a requirement that requires IE11 .. The problem is File object is not supported? Do you know which object I can use in javascript to replace the File ? Thanks |
Hi! i have a problem trying to preview an image that is not on the same folder with my page, i would like to know if it is possible and how. |
Maybe it helps someone. Using the plugin provided above just by adding the file to the queue it doenst tigger the event uploader.onAfterAddingFile(dummy);, you have to call it manually |
Hello! Sorry to bump this issue, I implemented this solution, however I couldn't not get it to refresh the list ? it does show my files if I add an item from the upload button or the drop zone. I am using angular but I do the request with jQuery (I know it's not the angular way but I will do refactoring soon) $.get(api_intern+'type=files',function(data){
var data = $.parseJSON(data).data;
if(data){
for(var i in data){
var fileItems = [];
fileItems[i] = new FileUploader.FileItem(uploader, {
dateModified: 'today',
size: data[i].size,
type: data[i].type,
name: data[i].name
});
fileItems[i].progress = 100;
fileItems[i].isUploaded = true;
fileItems[i].isReady = true;
fileItems[i].isSuccess = true;
uploader.queue.push(fileItems[i]);
uploader.onAfterAddingFile(fileItems[i]);
}
}
}); Another question I have is how do I remove it on the server also when I click the remove button, I looked in the code however I did not see if there is any remove item callback, sorry for bumping this, I see that other people got this working and I don't know exactly what they did, I did try to trigger the callbacks I saw (onAfterAddingFile and onAfterAddingAll) however they still don't show up. thanks in advance. |
Hello guys, I managed to solve the problem, you just need to call uploader._render(); after you add to the queue. data is my file array var fileItems = [];
for(var i in data){
var fileItem = new FileUploader.FileItem(uploader, {
dateModified: 'today',
size: data[i].size,
type: data[i].type,
name: data[i].name
});
fileItem.progress = 100;
fileItem.isUploaded = true;
fileItem.isSuccess = true;
fileItems.push(fileItem);
uploader.queue.push(fileItem);
uploader.onAfterAddingFile(fileItem);
}
uploader.onAfterAddingAll(fileItems);
uploader._render(); |
Hi, Appreciated your help on this. |
@xkidro can you create a jsfiddle so i can understand more thanks 😘 |
@mfundo hi sir do u have a jsfiddle so i can undestand more thanks |
@gerome0123 I can't make a jsfiddle, here is the full controler. 'use strict';
myApp.controller('FileUploadCtrl', ['$scope', 'FileUploader', function($scope, FileUploader) {
var id = $scope.$state.params.id;
var api_intern = api + 'table=pdf&id='+id+'&';
var uploader = $scope.uploader = new FileUploader({
url: api_intern+'type=upload'
});
$('.file-drop-zone').on('click',function() {
$('.file-drop-zone .hidden').click();
});
$.get(api_intern+'type=files',function(data){
var data = $.parseJSON(data).data;
if(data){
var fileItems = [];
for(var i in data){
var fileItem = new FileUploader.FileItem(uploader, data[i]);
fileItem.file.id = data[i].id;
fileItem.progress = 100;
fileItem.isUploaded = true;
fileItem.isSuccess = true;
fileItems.push(fileItem);
uploader.queue.push(fileItem);
uploader._onAfterAddingFile(fileItem);
}
uploader._onAfterAddingAll(fileItems);
uploader._render();
}
});
// CALLBACKS
uploader.onWhenAddingFileFailed = function(item /*{File|FileLikeObject}*/ , filter, options) {
//console.info('onWhenAddingFileFailed', item, filter, options);
};
uploader.onAfterAddingFile = function(fileItem) {
//console.info('onAfterAddingFile', fileItem);
};
uploader.onAfterAddingAll = function(addedFileItems) {
//console.info('onAfterAddingAll', addedFileItems);
};
uploader.onBeforeUploadItem = function(item) {
//console.info('onBeforeUploadItem', item);
};
uploader.onBeforeRemoveItem = function(item) {
if(item.isUploaded){
$.get(api_intern+'type=delete_file&file_id='+item.file.id);
}
//console.info('onBeforeRemoveItem', item);
};
uploader.onProgressItem = function(fileItem, progress) {
//console.info('onProgressItem', fileItem, progress);
};
uploader.onProgressAll = function(progress) {
//console.info('onProgressAll', progress);
};
uploader.onSuccessItem = function(fileItem, response, status, headers) {
fileItem.file.id = response.data.id;
if(response.data.name){
fileItem.file.name = response.data.name;
}
//console.info('onSuccessItem', fileItem, response, status, headers);
};
uploader.onErrorItem = function(fileItem, response, status, headers) {
//console.info('onErrorItem', fileItem, response, status, headers);
};
uploader.onCancelItem = function(fileItem, response, status, headers) {
//console.info('onCancelItem', fileItem, response, status, headers);
};
uploader.onCompleteItem = function(fileItem, response, status, headers) {
//console.info('onCompleteItem', fileItem, response, status, headers);
};
uploader.onCompleteAll = function() {
//console.info('onCompleteAll');
};
//console.info('uploader', uploader);
}]); |
@xkidro thanks for the reply can i see your view? |
In my case nothing works, I guess maybe there are recent changes in $http.get that makes all of the above code fail for me, anyway, after testing all code of the examples in this post, I was able to make it work: var url = 'directory/imagen.jpg'; $http.get(url, { responseType: "blob" }).then( var iname = data.config.url.substr(data.config.url.lastIndexOf('/') + 1); var file = new File([idata], iname, { type: itype}); uploader.addToQueue(file); }, That's all, addToQueue calls to onAfterAddingFile and render. In case you need to change file attributes like isUploaded, I think addToQueue options allow do it, but I was unable to change it, so instead I just use the next lines of code after the addToQueue call var dummy = uploader.queue[uploader.queue.length - 1]; dummy.progress = 100; Hope that helps someone. |
If you want to have $_FILES populated inside the PHP once you submit the data, you need to add the
|
Is there a way to pragmatically add files? Let's say there are some files on the server when pages load and I want to add them to be displayed.
The text was updated successfully, but these errors were encountered: