amazon s3 - Fine Uploader - objectProperties - Key -


i have 1 page whick give user add new car cars collection. user must add minimum 1 image car item.

in aws s3 service save images in path architecture:

bucket_name/cars/here_is_user_id/here_is_car_id/and here photos

i use fine uploader. , if add car in 2 step - going good

in 1 step add database car - , send server side userid , new car id. , in step 2 init fine uploader id:

below code:

(function () {     'use strict';     angular         .module('cars.services.fineuploader', ['ngresource'])         .factory('fineuploader', ['$resource', '$http', 'appconfig', function ($resource, $http, appconfig) {             return function (divid, templatename, autoupload, foldersbtn, uploadsuccesscallback, type, parentid, id) {                 var key = '';                 var keyexist = false;                 getkey();                  if (!qq.supportedfeatures.folderselection) {                     document.getelementbyid(foldersbtn).style.display = "none";                 }                 var uploader = new qq.s3.fineuploader({                     element: document.getelementbyid(divid),                     template: templatename,                     autoupload: autoupload,                     request: {                         endpoint: 'carsbucket.s3.amazonaws.com',                         accesskey: 'access',                     },                     extrabuttons: [                   {                       element: document.getelementbyid(foldersbtn),                       folders: true                   }                     ],                     signature: {                         endpoint: appconfig.apiurl + 'api/amazons3/getsignature'                     },                     uploadsuccess: {                         endpoint: uploadsuccesscallback()                     },                     iframesupport: {                         localblankpagepath: '/success.html'                     },                     objectproperties: {                         key: function (id) {                             var filename = uploader.getname(id);                             var ext = qq.getextension(filename);                             return key+ '/' + filename + "." + ext;                         }                     }                 });                 return {                      uploader: function () {                         return uploader;                     },                     startupload: function () {                         uploader.uploadstoredfiles();                     },                     inituploader: function () {                          while (!keyexist) {                             getkey();                         }                     }                  };                 function getkey() {                     var itemrequest = {                         "itemtype": type,                         "parentid": parentid,                         "itemid": id                     };                     $http.post("http://localhost:42309/api/amazons3/getitemkey", itemrequest).success(function (data, status) {                         key = data;                         keyexist = true;                     });                 }             }          }]); })(); 

and code how init service:

  function uploader(shopid, shopitemid) {                     vm.step = 2;                     uploader = fineuploader('s3fu', 'qq-template-gallery', false, 'foldersbutton', testcallback, 1, shopid, shopitemid);                    } 

now want add item logic in 1 step dont know how - because need init fineuploader - dont have carid , userid

.........


Comments