我正试图从Android for app上传视频到Facebook。 as3 facebook api有以下上传视频的方法
facebookMobile.uploadVideo(method:String, callback:Function = null, params:* = null)
params:* (default = null) — An object containing the title, description, fileName (including extension), and video (FileReference or ByteArray)
我正在使用cameraUi录制视频,并且正在返回文件的位置。根据api我需要使用fileReferance
或byteArray
传递此文件,因为我已经拥有文件的位置,我不想要任何类型的浏览功能。我无法创建byteArray
(以前从未使用过它)。我从Facebook收到353错误:you must select a video file
。
Bellow是我尝试创建bytearray
public function UICompleteHandler(event:MediaEvent):void
{
trace("Welcome back from the camera");
var media:MediaPromise = event.data;
trace("file info "+media.file.url + " - " + media.relativePath + " - " + media.mediaType);
filePath = media.file.url;
trace("Object encoding is: " + inBytes.objectEncoding + "\n\n" + "order file: \n\n");
readFileIntoByteArray(filePath, inBytes);
trace("length 1: "+inBytes.length);
trace("position 1: "+inBytes.position);
inBytes.position = 0; // reset position to beginning
//inBytes.uncompress(CompressionAlgorithm.DEFLATE);
//trace("position 2: "+inBytes.position);
//inBytes.position = 0; //reset position to beginning
trace (inBytes);
}
private function readFileIntoByteArray(fileName:String, data:ByteArray):void
{
var inFile:File = new File(fileName);
trace ("file to byte array "+ inFile.url);
trace ("file name var : "+fileName);
inStream.open(inFile , FileMode.READ);
inStream.readBytes(data);
inStream.close();
}
和视频上传代码:
public function handleUpload(ev:TouchEvent)
{
trace ("posting to facebook - FileName: "+ accessCamera.fileName + " - FilePath: " + accessCamera.filePath);
var params:Object ={
title:'test upload on FB api',
description:'test upload on FB api',
fileName: accessCamera.fileName,
video: accessCamera.inBytes
}
//trace ("params.video = "+params.video);
FacebookMobile.uploadVideo('me/videos', onComplete, params);
}
private function onComplete( result:Object, fail:Object ):void {
trace("facebook post onComplete called" );
if (result)
{
//result.id is id of post that was just posted
trace ("great");
}
else if (fail)
{
trace("post Failed");
trace('code: '+fail.error.code);
trace('message: '+fail.error.message);
trace('type: '+fail.error.type);
}
}
答案 0 :(得分:1)
无需将其转换为ByteArray
。 File
是一个AIR-only类,旨在允许您直接访问文件系统(正如您已经在做的那样)。当File
扩展FileReference
时,您只需传递已有的File
对象。