精细上传器 - objectProperties - 键

时间:2016-01-24 21:35:06

标签: amazon-s3 fine-uploader

我有1页whick给用户添加新车到他的汽车收藏。 用户必须在此汽车项目中添加最少1张图片。

在AWS S3服务中,我将图像保存在此路径架构中:

bucket_name / cars / HERE_IS_USER_ID / HERE_IS_CAR_ID /这里是照片

我使用精美的上传器。 如果我确实在两步中添加汽车 - 一切都很顺利

在一步中,我添加到我的数据库汽车 - 并从服务器端发送userId和新车ID。 然后在第2步中,我使用此ID启动Fine uploader:

以下代码:

(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;
                    });
                }
            }

        }]);
})();

这是我如何启动此服务的代码:

  function Uploader(shopId, shopItemId) {
                    vm.step = 2;
                    uploader = FineUploader('s3FU', 'qq-template-gallery', false, 'foldersButton', testCallback, 1, shopId, shopItemId);



                }

现在我想在一步中完成所有ADD ITEM逻辑 但我不知道它是怎么做的 - 因为我需要初始化FineUploader - 但我没有carId和UserId

.........

0 个答案:

没有答案