Jquery文件在Chunks中压缩和上传

时间:2015-10-12 12:06:50

标签: javascript jquery file-upload compression chunks

我一直在尝试实现文件压缩,然后在Chunks中上传压缩文件。

对于文件压缩,我使用过:

var maxWidth = 960, maxHeight = 960, imageWidth = image.width,
    imageHeight = image.height;

                if (imageWidth > imageHeight) {
                    if (imageWidth > maxWidth) {
                        imageHeight *= maxWidth / imageWidth;
                        imageWidth = maxWidth;
                    }
                }
                else {
                    if (imageHeight > maxHeight) {
                        imageWidth *= maxHeight / imageHeight;
                        imageHeight = maxHeight;
                    }
                }

                var canvas = document.createElement('canvas');
                canvas.width = imageWidth;
                canvas.height = imageHeight;

                var ctx = canvas.getContext("2d");
                ctx.drawImage(this, 0, 0, imageWidth, imageHeight);

                // The resized file ready for upload
                var finalFile = canvas.toDataURL(fileType);

这将返回base64格式。

但是对于Chunks中的文件上传,我使用了一些只接受文件但不接受base64格式的技术:(

我的Chunks上传代码将是这样的:

cful = Object.create(chunkedFileUploader);
cful.init(item.file(), item.messageid(), '', item.messageid(), false, item.height, item.width);
//self.uploaderCollection.push(cful);
cful.uploadMetaData();

有没有办法:

1)压缩后得到一个文件而不是base64 2)接受base64 for chunk上传。
3)或者还有其他更好的方法可以解决这些复杂问题吗?

提前致谢:)

0 个答案:

没有答案