上传前修改 FileReference.data bytearray 无效
Modify FileReference.data bytearray before upload not working
我有一个简单的文件浏览器,允许用户 select 本地图像,我想在上传到服务器之前处理这个图像。我遇到的问题是,当我调用 fileReference.upload() 时,它似乎将原始文件而不是修改后的字节数组上传到用户的硬盘上。我是不是做错了什么,这是预期的行为还是错误?
作为一个非常基本的测试,如果我做这样的事情,我仍然会得到原始文件:
// load the file in to memory
_fileReference.load();
// ... on file reference loaded
trace(_fileReference.data.length); // 230189
_fileReference.data.clear();
trace(_fileReference.data.length); // 0
// With this next line commented out I would expect a 0 bytes file, or an error or something, but instead it happily uploads the original file.
//_fileReference.data.writeBytes(myNewByteArray);
_fileReference.upload(myURLRequest);
根据这个 post Manipulate file data (byte array) 这应该可行...
非常感谢任何想法!
干杯,
西蒙
仔细阅读 FileReference documentation。它说数据 属性 是只读的。这意味着您不能在上传之前直接更改图片。
要更改图片,您可以使用 Loader::loadBytes() to get an instance of Bitmap, then change it the way you want, encode it 然后上传到您的服务器。
我有一个简单的文件浏览器,允许用户 select 本地图像,我想在上传到服务器之前处理这个图像。我遇到的问题是,当我调用 fileReference.upload() 时,它似乎将原始文件而不是修改后的字节数组上传到用户的硬盘上。我是不是做错了什么,这是预期的行为还是错误?
作为一个非常基本的测试,如果我做这样的事情,我仍然会得到原始文件:
// load the file in to memory
_fileReference.load();
// ... on file reference loaded
trace(_fileReference.data.length); // 230189
_fileReference.data.clear();
trace(_fileReference.data.length); // 0
// With this next line commented out I would expect a 0 bytes file, or an error or something, but instead it happily uploads the original file.
//_fileReference.data.writeBytes(myNewByteArray);
_fileReference.upload(myURLRequest);
根据这个 post Manipulate file data (byte array) 这应该可行...
非常感谢任何想法!
干杯, 西蒙
仔细阅读 FileReference documentation。它说数据 属性 是只读的。这意味着您不能在上传之前直接更改图片。
要更改图片,您可以使用 Loader::loadBytes() to get an instance of Bitmap, then change it the way you want, encode it 然后上传到您的服务器。