Jquery错误,图片上传确实有效

时间:2014-01-02 10:19:16

标签: javascript jquery node.js amazon-s3

奇怪的错误,我使用blueimp jquery文件上传,将文件从客户端上传到Node.js然后再上传到Amazon S3存储。

代码运行完美,文件确实到达了亚马逊s3,但在插件的客户端我得到了这个错误:Error SyntaxError: Unexpected token S

我正在使用的Node.js代码如下:

app.post('/upload', function(req, res) {
    fs.readFile(req.files.files[0].path, function (err, data) {
        var imageName = req.files.files[0].name
        /// If there's an error
        if(!imageName){
            console.log("There was an error")
            res.redirect("/");
            res.end();
        } else {
            var img_path = req.files.files[0].path;
           var file_read  = fs.readFile(img_path, function(err, data){
               var BucketName = 'webwedding/'+SSName;
               s3.createBucket({Bucket: BucketName}, function() {
                   var params = {Bucket: BucketName,ACL: "public-read" , Key: imageName, Body: data};
                   s3.putObject(params, function(err, data) {
                       res.writeHead(200, {'Content-Type': 'text/plain'});
                       if (err) {
                           console.log(err)
                           res.end(err);
                       }
                       else      {
                           console.log('Uploaded ' + imageName +' To '+SSName);
                           res.end('Successfully uploaded data to webwedding\n');
                       }
                   });
               });
           });
        }
    });
});

我现在明白我需要JSON.stringly结果,但只能设法创建正确的res.end结果!试图关注Blueimp support

* 编辑: *尝试添加模板以检查结果:

                   var files = [
                       {
                           "name": "picture1.jpg",
                           "size": 902604,
                           "url": "http:\/\/example.org\/files\/picture1.jpg",
                           "thumbnailUrl": "http:\/\/example.org\/files\/thumbnail\/picture1.jpg",
                           "deleteUrl": "http:\/\/example.org\/files\/picture1.jpg",
                           "deleteType": "DELETE"
                       }]
                   res.end(JSON.stringify(files));

在客户端给我这个错误:

Error Empty file upload result

错误来自fileupload.ui代码,希望它不会太长,但我想我必须展示它,所以也许有人可以弄明白:

if (data.context) {
                    data.context.each(function (index) {
                        var file = files[index] ||
                                {error: 'Empty file upload result'};
                        deferred = that._addFinishedDeferreds();
                        that._transition($(this)).done(
                            function () {
                                var node = $(this);
                                template = that._renderDownload([file])
                                    .replaceAll(node);
                                that._forceReflow(template);
                                that._transition(template).done(
                                    function () {
                                        data.context = $(this);
                                        that._trigger('completed', e, data);
                                        that._trigger('finished', e, data);
                                        deferred.resolve();
                                    }
                                );
                            }
                        );
                    });

0 个答案:

没有答案
相关问题