Nhat Nguyen
- Forum posts: 5
Jun 1, 2012, 4:31:04 PM via Website
Jun 1, 2012 4:31:04 PM via Website
Hi all,
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, this get an OutOfMemory error and the app failed. In Logcat, the Facebook's line-code has problem, issue out of momory error.
My code, upload small video (~ 2M successful.
From Facebook SDK for Android, error line is marked below (inside method openOrl):
Please help me with this problem, thanks a lot ^_^.
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, this get an OutOfMemory error and the app failed. In Logcat, the Facebook's line-code has problem, issue out of momory error.
My code, upload small video (~ 2M successful.
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 ^_^.
— modified on Jun 1, 2012, 4:32:03 PM
Recommended editorial content
With your consent, external content is loaded here.
By clicking on the button above, you agree that external content may be displayed to you. Personal data may be transmitted to third-party providers in the process. You can find more information about this in our Privacy Policy.