Expose public API method to add canned files #1191

Closed
rnicholus opened this Issue Apr 23, 2014 · 11 comments

Projects

None yet

2 participants

@rnicholus
Member

Currently, canned file data must come from a server. If the initial file list feature is enabled, Fine Uploader sends a GET request on init (and on reset), expecting JSON data to represent files uploaded successfully in a previous session. It might be useful to allow successfully upload metadata to be persisted to and read from localStorage as an alternative. Obviously, this is not possible in browsers that don't support localStorage such as IE7.

Another option may be to provide an API method where integrators can passed canned file data at any time. This allows the data to be stored anywhere.

@rnicholus
Member

Current plan is to simply provide an API method.

@rnicholus rnicholus changed the title from Allow canned files to be persisted/read from localStorage to 2 - Allow canned files to be persisted/read from localStorage May 6, 2014
@rnicholus rnicholus added 2 - Do and removed 0 - Discuss labels May 6, 2014
@rnicholus rnicholus changed the title from 2 - Allow canned files to be persisted/read from localStorage to Allow canned files to be persisted/read from localStorage Mar 17, 2016
@rnicholus rnicholus added this to the 5.6.0 milestone Mar 17, 2016
@rnicholus
Member

@ludofleury & @alphestdev Can one or both of you commit to verifying that that API method I will add in this issue addresses your needs?

@alphestdev

@rnicholus I'll gladly implement and verify this as soon as it's released.

@rnicholus
Member

...this would be pre-release testing. I'll make sure you get access to the pre-release version and will wait for your feedback before release.

@rnicholus rnicholus changed the title from Allow canned files to be persisted/read from localStorage to Expose public API method to add canned files Mar 17, 2016
@rnicholus
Member

I've pushed a pre-release - 5.6.0-1 which contains a new API method - addInitialFiles. Please let me know if this is working as expected. Upon verification, I'll formally release this as Fine Uploader 5.6.0.

@rnicholus rnicholus added a commit that referenced this issue Mar 17, 2016
@rnicholus rnicholus docs(initial files): Update initial files feature page
closes #1191
[skip ci]
db6d667
@alphestdev

Hi Ray. The method you provided in v5.6.0.1 works well, but does not meet my needs because it doesn't return the id's of added files, which we use to maintain our list of added files to prevent duplicates (like you suggested somewhere on stackoverflow) and other needs.

Take for example our current implementation:

var addedFiles = []; // Keep track of all added files
var uploader = ...;
$$('.js-file-upload-initial-file[data-inputname="'+ inputName +'"]').each(function(hiddenField){
  var id = uploader._addCannedFile({
    uuid: hiddenField.get('data-uuid'),
    name: hiddenField.get('data-filename'),
    size: hiddenField.get('data-size'),
    thumbnailUrl: hiddenField.get('data-thumbnail-url')
  });
  addedFiles[id] = [hiddenField.get('data-filename'), hiddenField.get('data-size'), hiddenField];
});
uploader._templating.addCacheToDom();

This cannot be programmed using only addInitialFiles(files), because this function does not return id's even if the canned files are added one by one.

@rnicholus
Member

You can get a list of all files tracked by the uploader (as well as each file's name, size, uuid, id, etc) using the getUploads API method.

@alphestdev

Using getUploads method I get the added file records with id's correctly. It's not performance friendly because now I have to use 2 loops instead of one, but it works.

@rnicholus
Member

Unless you are looping through thousands of files, there is likely no perf difference, but I'm really not clear why you are looping over anything. All you need to do is pass your initial file list via the addInitialFilescmethod. I'd advise stepping back and taking a close look at your code to see how it can be improved. Perhaps there is a much better approach to solve whatever problem you are trying to solve, given the available API.

Thanks for the update, I will release this new version next week.

@rnicholus
Member

Also if you post a question on stack overflow under the fine-uploader tag, explain what you are trying to do with all of these loops (taking into account use of the API method I just added), and show all of your code, I can help you find a better approach as well. This is an ideal use case for SO.

@rnicholus rnicholus added a commit that closed this issue Mar 24, 2016
@rnicholus rnicholus feat(initial files): Allow initial files to be added via the API
Introduces a new API method - addInitialFiles.
closes #1191
8a4281d
@rnicholus rnicholus closed this in 8a4281d Mar 24, 2016
@rnicholus
Member

This has been released as part of 5.6.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment