FileReference和HttpService浏览图像修改然后上传

发布于 2024-08-06 10:14:47 字数 582 浏览 3 评论 0原文

我正在尝试做一个图像上传器,用户可以:
- 使用button.browse浏览本地文件
- 选择一个并将其另存为文件参考。
- 然后我们执行 FileReference.load() 然后将数据绑定到我们的图像控件。
- 在我们对其进行旋转并更改图像数据之后。
- 最后我们将其上传到服务器。

要更改图像的数据,我获取显示图像的矩阵并对其进行转换,然后我重新使用新矩阵并将其绑定到我的旧图像:

private function TurnImage():void
{ 
    //Turn it
    var m:Matrix = _img.transform.matrix;
    rotateImage(m);
    _img.transform.matrix = m;
}

现在的问题是我真的不知道如何将数据发送为将文件发送到我的服务器会导致其未存储在 FileReference 中,并且 FileReference 内的数据是只读的,因此我们无法更改它或创建新文件,因此我无法使用 .upload();。

然后我尝试了 HttpService.send 但我不知道如何发送文件而不是 mxml。

I am trying to do an image uploader, user can:
- browse local file with button.browse
- select one and save it as a FileReference.
- then we do FileReference.load() then bind the data to our image control.
- after we make a rotation on it and change the data of image.
- and to finish we upload it to a server.

To change the data of image i get the matrix of the displayed image and transform it then i re-use the new matrix and bind it to my old image:

private function TurnImage():void
{ 
    //Turn it
    var m:Matrix = _img.transform.matrix;
    rotateImage(m);
    _img.transform.matrix = m;
}

Now the mater is that i really don't know how to send the data as a file to my server cause its not stored in the FileReference and data inside FileReference is readOnly so we can't change it or create a new, so i can't use .upload();.

Then i tried HttpService.send but i can't figure out how you send a file and not a mxml.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

枯寂 2024-08-13 10:14:47

您可以使用 URLLoader 将 Binary ByteArray 发送到服务器,例如:

var urlRequest : URLRequest = new URLRequest();
urlRequest.url = 'path to your server';
urlRequest.contentType = 'multipart/form-data; boundary=' + UploadPostHelper.getBoundary();
urlRequest.method = URLRequestMethod.POST;
urlRequest.data = UploadPostHelper.getPostData( 'image.jpg', byteArray );
urlRequest.requestHeaders.push( new URLRequestHeader( 'Cache-Control', 'no-cache' ) );

// create the image loader & send the image to the server:<br />
var urlLoader : URLLoader = new URLLoader();
urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
urlLoader.load( urlRequest );

首先获取图像的位图数据:

// set up a new bitmapdata object that matches the dimensions of the captureContainer;
var bmd : BitmapData = new BitmapData( captureContainer.width, captureContainer.height, true, 0xFFFFFFFF );

// draw the bitmapData from the captureContainer to the bitmapData object:<br />
bmd.draw( captureContainer, new Matrix(), null, null, null, true );

然后获取 byteArray:

var byteArray : ByteArray = new JPGEncoder( 90 ).encode( bmd );

并使用上面的 URLLoader 代码将图像发送到服务器。

它将正常工作,只是您无法像从 FileReference.upload 获得的那样获得文件上传进度。如果您可以使用 URLLoader 进行上传,请在此处发布您的答案。

You can use URLLoader to send Binary ByteArray to server, like:

var urlRequest : URLRequest = new URLRequest();
urlRequest.url = 'path to your server';
urlRequest.contentType = 'multipart/form-data; boundary=' + UploadPostHelper.getBoundary();
urlRequest.method = URLRequestMethod.POST;
urlRequest.data = UploadPostHelper.getPostData( 'image.jpg', byteArray );
urlRequest.requestHeaders.push( new URLRequestHeader( 'Cache-Control', 'no-cache' ) );

// create the image loader & send the image to the server:<br />
var urlLoader : URLLoader = new URLLoader();
urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
urlLoader.load( urlRequest );

First get bitmapdata for the image:

// set up a new bitmapdata object that matches the dimensions of the captureContainer;
var bmd : BitmapData = new BitmapData( captureContainer.width, captureContainer.height, true, 0xFFFFFFFF );

// draw the bitmapData from the captureContainer to the bitmapData object:<br />
bmd.draw( captureContainer, new Matrix(), null, null, null, true );

Then get byteArray:

var byteArray : ByteArray = new JPGEncoder( 90 ).encode( bmd );

and use the above URLLoader code to send image to server.

It will work fine, except you wouldn't get the file upload progress like the one you get from FileReference.upload. If you can make upload progress work using URLLoader, please post your answer here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文