我需要在一个HTTP Post中做一个HTTP帖子的信息,包括多个文件的字符串字节表示。我收到了很多字节分配错误,并想知道是否有更好的方法来存储这些信息以便以后发布到服务器上?
我基本上已经拍摄了很多图片文件,我将它们打包成一个格式为的单个HTTP Post字符串:
name="string byte representation of picture file"×tamp="time"&gps="latitude""longitude",
等
logcat的:
03-09 22:26:41.329: E/dalvikvm-heap(8716): Out of memory on a 5932438-byte allocation.
03-09 22:26:41.329: I/dalvikvm(8716): "main" prio=5 tid=1 RUNNABLE
03-09 22:26:41.329: I/dalvikvm(8716): | group="main" sCount=0 dsCount=0 s=N obj=0x40020ba0 self=0xddd0
03-09 22:26:41.329: I/dalvikvm(8716): | sysTid=8716 nice=0 sched=0/0 cgrp=unknown handle=-1345025972
03-09 22:26:41.329: I/dalvikvm(8716): at java.lang.AbstractStringBuilder.enlargeBuffer(AbstractStringBuilder.java:~97)
03-09 22:26:41.329: I/dalvikvm(8716): at java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:157)
03-09 22:26:41.329: I/dalvikvm(8716): at java.lang.StringBuilder.append(StringBuilder.java:217)
03-09 22:26:41.329: I/dalvikvm(8716): at mfc.generalguixapi8.SaveData2.saveData(SaveData2.java:169)
03-09 22:26:41.329: I/dalvikvm(8716): at mfc.generalguixapi8.SaveData2.onCreate(SaveData2.java:34)
03-09 22:26:41.329: I/dalvikvm(8716): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-09 22:26:41.329: I/dalvikvm(8716): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
03-09 22:26:41.329: I/dalvikvm(8716): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
03-09 22:26:41.329: I/dalvikvm(8716): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
03-09 22:26:41.329: I/dalvikvm(8716): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
03-09 22:26:41.329: I/dalvikvm(8716): at android.os.Handler.dispatchMessage(Handler.java:99)
03-09 22:26:41.329: I/dalvikvm(8716): at android.os.Looper.loop(Looper.java:123)
03-09 22:26:41.329: I/dalvikvm(8716): at android.app.ActivityThread.main(ActivityThread.java:4627)
03-09 22:26:41.339: I/dalvikvm(8716): at java.lang.reflect.Method.invokeNative(Native Method)
03-09 22:26:41.339: I/dalvikvm(8716): at java.lang.reflect.Method.invoke(Method.java:521)
03-09 22:26:41.339: I/dalvikvm(8716): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
03-09 22:26:41.339: I/dalvikvm(8716): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
03-09 22:26:41.339: I/dalvikvm(8716): at dalvik.system.NativeStart.main(Native Method)
03-09 22:26:41.339: W/dalvikvm(8716): threadid=1: thread exiting with uncaught exception (group=0x40020ac0)
03-09 22:26:41.339: E/AndroidRuntime(8716): FATAL EXCEPTION: main
03-09 22:26:41.339: E/AndroidRuntime(8716): java.lang.OutOfMemoryError
03-09 22:26:41.339: E/AndroidRuntime(8716): at java.lang.AbstractStringBuilder.enlargeBuffer(AbstractStringBuilder.java:97)
03-09 22:26:41.339: E/AndroidRuntime(8716): at java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:157)
03-09 22:26:41.339: E/AndroidRuntime(8716): at java.lang.StringBuilder.append(StringBuilder.java:217)
03-09 22:26:41.339: E/AndroidRuntime(8716): at mfc.generalguixapi8.SaveData2.saveData(SaveData2.java:169)
03-09 22:26:41.339: E/AndroidRuntime(8716): at mfc.generalguixapi8.SaveData2.onCreate(SaveData2.java:34)
03-09 22:26:41.339: E/AndroidRuntime(8716): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-09 22:26:41.339: E/AndroidRuntime(8716): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
03-09 22:26:41.339: E/AndroidRuntime(8716): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
03-09 22:26:41.339: E/AndroidRuntime(8716): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
03-09 22:26:41.339: E/AndroidRuntime(8716): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
03-09 22:26:41.339: E/AndroidRuntime(8716): at android.os.Handler.dispatchMessage(Handler.java:99)
03-09 22:26:41.339: E/AndroidRuntime(8716): at android.os.Looper.loop(Looper.java:123)
03-09 22:26:41.339: E/AndroidRuntime(8716): at android.app.ActivityThread.main(ActivityThread.java:4627)
03-09 22:26:41.339: E/AndroidRuntime(8716): at java.lang.reflect.Method.invokeNative(Native Method)
03-09 22:26:41.339: E/AndroidRuntime(8716): at java.lang.reflect.Method.invoke(Method.java:521)
03-09 22:26:41.339: E/AndroidRuntime(8716): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
03-09 22:26:41.339: E/AndroidRuntime(8716): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
03-09 22:26:41.339: E/AndroidRuntime(8716): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:0)
可以使用Sending file > 1MB using HTTP POST
解决问题我在上面的链接中遇到了OutofMemory问题,并通过将数据保存到FileOutputStream并以块的形式将信息发送到服务器来解决它。