当前位置:编程学习 > 网站相关 >>

上传视频到优酷服务器时出错,求高手指点迷津~

在优酷的上传视频API中(WINFORM),要执行一系列的操作,前面已陆续测试成功,现在在一个叫“upload_slice”的API中需要传递二进制数据,他的API具体说明如下:

upload_slice

InterfacePOST http://gX.upload.youku.com/gupload/upload_slice?< .. parameters .. >
< .. BINARY DATA .. > 

 Parameters

 upload_token: string, MUST provide.

 slice_task_id: int, MUST provide. the slice upload task ID. 

 offset: int64, MUST provide. the offset in the source file. 

 length: int, MUST provide. the data length. 

 crc: string, CRC32 of the data slice in hex string. default is empty string (””).

 hash: string, MD5 of the data slice in hex string. default is empty string (””).

 data: binary. 

 Note: One of CRC or HASH is recommented for error testing and slice re-uploading.

 Return Value

 error: object. Only returned when error occured.

 code: int. 

 type: string. 

 description: string. 

 slice_task_id: int, MUST provide. the next slice upload task ID. 

 offset: int64, MUST provide. the offset of the next slice in the source file to upload. 

 length: int, MUST provide. the data length of the next slice to upload. 

 transferred: int64. the data length that already uploaded. 

 finished: boolen, whether or not the file is totally uploaded.

 Error Codes

 120010205 - Invalid upload session id

 120010212 - Internal error: memory error

 120010218 - CRC check error

 120010219 - Resource unavailable

 120010221 - Duplicated operation

 120010224 - Bad request

 120010225 - Hash check error

 See Error Definition for full list of error definitions.

 Sample (for demo only; layout for ease of reading)
POST /gupload/upload_slice?upload_token=1a2b3c4d
&slice_task_id=1328792850123
&offset=12345678
&length=12345
&crc=dfc6f27b
Host: g01.upload.youku.com

< .. BINARY DATA .. >

----

201 Created

{ "slice_task_id": 1328793281567,
  "offset": 12358023,
  "length": 12345,
  "transferred": 12358023,
  "finished": false }

现在的问题是,如果把包含“文本”和二进制数据的内容一起POST到服务器?
难道是把2部分分开再合并起来发送?如我下面的代码所示:

   /// <summary>
        /// 合并数组
        /// </summary>
        /// <param name="first"></param>
        /// <param name="second"></param>
        /// <returns></returns>
        private byte[] mergerArray(byte[] first, byte[] second)
        {
            byte[] result = new byte[first.Length + second.Length];
            first.CopyTo(result, 0);
            second.CopyTo(result, first.Length);
            return result;
        }

        private void btn_upload_slice_Click(object sender, EventArgs e)
        {
            //upload_slice
            byte[] data2 = File.ReadAllBytes(file_name);

            Encoding encoding = Encoding.UTF8;

            uint crc = my_CRC32.CalculateDigest(data2, (uint)0,length);
            //MessageBox.Show(crc.ToString());
            string postData = "upload_token=" + upload_token + "\r\n";
            postData += ("&slice_task_id=" + slice_task_id + "\r\n");
            postData += ("&offset=" + offset + "\r\n");
            postData += ("&length=" + length + "\r\n");
            postData += ("&crc=" + crc + "\r\n");
            //postData += ("&data=" + "\r\n");
            //MessageBox.Show(postData);

            //postData += File.ReadAllBytes(file_name)+ "\r\n";

            byte[] data = encoding.GetBytes(postData);

            string content = ZdSoft.Framework.Helper.HttpRequest.DoPostRequest("http://g" +
                             gX + ".up.youku.com/gupload/upload_slice",
                             mergerArray(data, data2), 1);
            //MessageBox.Show(content);
            btn_upload_slice.Enabled = false;
        }


其中,ZdSoft.Framework.Helper.HttpRequest.DoPostRequest是我自己的类,发送POST请求的,mergerArray是合并数组数据用的,但是服务器一直返回400,我要怎么解决?求高手指点! upload 优酷 视频上传 二进制 post --------------------编程问答-------------------- 是把参数弄成地址,再把二进制post过去!
补充:云计算 ,  OpenAPI
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,