I am develop a demo about Facebook SDK from my app. Now, my app can: post status, image , video to my wall or friend's wall.
But, when I am testing with large video size (about 12 M
My code, upload small video (~ 2M
1byte data[] = readVideoData(videoFilePath);
2 if (data == null) return;
3 else Log.i(TAG, "-Video byte array length = " + data.length);
4
5 Bundle bundle = new Bundle();
6 bundle.putString(Facebook.TOKEN, mFacebook.getAccessToken());
7 bundle.putString("description", status);
8 bundle.putString("filename", new File(videoFilePath).getName());
9 bundle.putByteArray("video", data);
10
11 mFacebookRunner.request("me/videos", bundle, "POST",
12 new FBOperationRequestListener(), null);
2 if (data == null) return;
3 else Log.i(TAG, "-Video byte array length = " + data.length);
4
5 Bundle bundle = new Bundle();
6 bundle.putString(Facebook.TOKEN, mFacebook.getAccessToken());
7 bundle.putString("description", status);
8 bundle.putString("filename", new File(videoFilePath).getName());
9 bundle.putByteArray("video", data);
10
11 mFacebookRunner.request("me/videos", bundle, "POST",
12 new FBOperationRequestListener(), null);
From Facebook SDK for Android, error line is marked below (inside method openOrl):
1public static String openUrl(String url, String method, Bundle params)
2 throws MalformedURLException, IOException {
3......
4
5conn.setRequestMethod("POST");
6 conn.setRequestProperty(
7 "Content-Type",
8 "multipart/form-data;boundary="+strBoundary);
9 conn.setDoOutput(true);
10 conn.setDoInput(true);
11 conn.setRequestProperty("Connection", "Keep-Alive");
12 conn.connect();
13 os = new BufferedOutputStream(conn.getOutputStream());
14
15 os.write(("--" + strBoundary +endLine).getBytes());
16 os.write((encodePostBody(params, strBoundary)).getBytes());
17 os.write((endLine + "--" + strBoundary + endLine).getBytes());
18
19 if (!dataparams.isEmpty()) {
20
21 for (String key: dataparams.keySet()){
22// os.write(("Content-Disposition: form-data; filename=\"" + key + "\"" + endLine).getBytes());
23 os.write(("Content-Disposition: form-data; filename=\"" + (filename != null ? filename : key) + "\"" + endLine).getBytes());
24 os.write(("Content-Type: content/unknown" + endLine + endLine).getBytes());
25
26 (***) os.write(dataparams.getByteArray(key)); // Out Of Memory here
27
28 os.write((endLine + "--" + strBoundary + endLine).getBytes());
29
30 }
31 }
32 os.flush();
That line get data from Bundle we put before (array of byte).2 throws MalformedURLException, IOException {
3......
4
5conn.setRequestMethod("POST");
6 conn.setRequestProperty(
7 "Content-Type",
8 "multipart/form-data;boundary="+strBoundary);
9 conn.setDoOutput(true);
10 conn.setDoInput(true);
11 conn.setRequestProperty("Connection", "Keep-Alive");
12 conn.connect();
13 os = new BufferedOutputStream(conn.getOutputStream());
14
15 os.write(("--" + strBoundary +endLine).getBytes());
16 os.write((encodePostBody(params, strBoundary)).getBytes());
17 os.write((endLine + "--" + strBoundary + endLine).getBytes());
18
19 if (!dataparams.isEmpty()) {
20
21 for (String key: dataparams.keySet()){
22// os.write(("Content-Disposition: form-data; filename=\"" + key + "\"" + endLine).getBytes());
23 os.write(("Content-Disposition: form-data; filename=\"" + (filename != null ? filename : key) + "\"" + endLine).getBytes());
24 os.write(("Content-Type: content/unknown" + endLine + endLine).getBytes());
25
26 (***) os.write(dataparams.getByteArray(key)); // Out Of Memory here
27
28 os.write((endLine + "--" + strBoundary + endLine).getBytes());
29
30 }
31 }
32 os.flush();
Please help me with this problem, thanks a lot ^_^.
