gpt4 book ai didi

java - 上传文件超过300M时应用程序崩溃

转载 作者:行者123 更新时间:2023-12-01 18:51:26 29 4
gpt4 key购买 nike

当我选择上传 400M 文件时,我的应用程序崩溃了,小于 300M 上传正常

我改变了这个

int maxBufferSize =  10 * 10241 * 1024;

int maxBufferSize =   10241 * 1024;

还是同样的问题

我是不是错过了什么?

protected String doInBackground(String... urls) {

String upLoadServerUri = upApi.uploadUrl;
String fileName = this.file_path;
HttpURLConnection connection = null;
DataOutputStream outputStream = null;
String lineEnd = "\r\n";
String twoHyphens = "--";
String boundary = "*****";
int bytesRead, bytesAvailable, bufferSize;
byte[] buffer;
int maxBufferSize = 10 * 10241 * 1024;
File sourceFile = new File(fileName);
int sentBytes = 0;
long fileSize = sourceFile.length();

try
{
FileInputStream fileInputStream = new FileInputStream(new File(fileName));

URL url = new URL(upLoadServerUri);
connection = (HttpURLConnection) url.openConnection();

// Allow Inputs & Outputs
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setUseCaches(false);
connection.setChunkedStreamingMode(1024);
// Enable POST method
connection.setRequestMethod("POST");

connection.setRequestProperty("Connection", "Keep-Alive");
connection.setRequestProperty("Content-Type", "multipart/form-data;boundary="+boundary);

outputStream = new DataOutputStream( connection.getOutputStream() );
outputStream.writeBytes(twoHyphens + boundary + lineEnd);
outputStream.writeBytes("Content-Disposition: form-data; name=\"file[]\";filename=\""+ fileName + "\"" + lineEnd);
outputStream.writeBytes(lineEnd);

buffer = new byte[maxBufferSize];

while (true)
{
int bytesToRead = Math.min(maxBufferSize, fileInputStream.available());

// Break if complete
if(bytesToRead == 0){ break; }

// Read bytes
bytesRead = fileInputStream.read(buffer, 0, bytesToRead);

// Write bytes
outputStream.write(buffer, 0, bytesRead);

// Update progress dialog
sentBytes += bytesRead;

// Publish progress
double progress = (double)sentBytes / fileSize;
publishProgress((int)progress);
}
<小时/>
04-04 23:11:24.664: E/OMX-VDEC-1080P(217): ION: alloc_data: handle(0xE4904BC0), len(368640), align(8192), flags(0x2000100), fd_data: handle(0xe4904bc0), fd(0x46)
04-04 23:11:24.664: E/OMX-VDEC-1080P(217): Allocate done for all i/p buffers
04-04 23:11:24.664: E/OMX-VDEC-1080P(217): Allocate done for all o/p buffers
04-04 23:11:24.664: E/OMX-VDEC-1080P(217): OMX_CommandStateSet complete, m_state = 2
04-04 23:11:24.664: E/OMX-VDEC-1080P(217): send_command: Recieved a Command from Client
04-04 23:11:24.664: E/OMX-VDEC-1080P(217): send_command_proxy(): cmd = 0, Current State 2, Expected State 3
04-04 23:11:24.664: E/OMX-VDEC-1080P(217): send_command_proxy(): OMX_CommandStateSet issued
04-04 23:11:24.664: E/OMX-VDEC-1080P(217): Current State 2, Expected State 3
04-04 23:11:24.664: E/OMX-VDEC-1080P(217): send_command_proxy(): Idle-->Executing
04-04 23:11:24.664: E/OMX-VDEC-1080P(217): send_command: Command Processed
04-04 23:11:24.664: E/OMX-VDEC-1080P(217): Rxd OMX_COMPONENT_GENERATE_START_DONE
04-04 23:11:24.664: E/OMX-VDEC-1080P(217): Rxd i/p EOS, Notify Driver that EOS has been reached
04-04 23:11:24.694: E/OMX-VDEC-1080P(217): Output EOS has been reached
04-04 23:11:24.694: E/OMX-VDEC-1080P(217): Rxd OMX_COMPONENT_GENERATE_EOS_DONE
04-04 23:11:24.704: E/OMX-VDEC-1080P(217): send_command: Recieved a Command from Client
04-04 23:11:24.704: E/OMX-VDEC-1080P(217): send_command_proxy(): cmd = 0, Current State 3, Expected State 2
04-04 23:11:24.704: E/OMX-VDEC-1080P(217): send_command_proxy(): OMX_CommandStateSet issued
04-04 23:11:24.704: E/OMX-VDEC-1080P(217): Current State 3, Expected State 2
04-04 23:11:24.704: E/OMX-VDEC-1080P(217): Command Recieved in OMX_StateExecuting
04-04 23:11:24.704: E/OMX-VDEC-1080P(217): send_command_proxy(): Executing --> Idle
04-04 23:11:24.704: E/OMX-VDEC-1080P(217): Driver flush i/p Port complete
04-04 23:11:24.704: E/OMX-VDEC-1080P(217): Initiate Input Flush
04-04 23:11:24.704: E/OMX-VDEC-1080P(217): Reset all the variables before flusing
04-04 23:11:24.704: E/OMX-VDEC-1080P(217): Initialize parser
04-04 23:11:24.704: E/OMX-VDEC-1080P(217): OMX flush i/p Port complete PenBuf(0)
04-04 23:11:24.704: E/OMX-VDEC-1080P(217): Driver flush o/p Port complete
04-04 23:11:24.704: E/OMX-VDEC-1080P(217): Initiate Output Flush
04-04 23:11:24.704: E/OMX-VDEC-1080P(217): OMX flush o/p Port complete PenBuf(0)
04-04 23:11:24.704: E/OMX-VDEC-1080P(217): Rxd OMX_COMPONENT_GENERATE_STOP_DONE
04-04 23:11:24.704: E/OMX-VDEC-1080P(217): send_command: Command Processed
04-04 23:11:24.704: E/OMX-VDEC-1080P(217): send_command: Recieved a Command from Client
04-04 23:11:24.704: E/OMX-VDEC-1080P(217): send_command_proxy(): cmd = 0, Current State 2, Expected State 1
04-04 23:11:24.704: E/OMX-VDEC-1080P(217): send_command_proxy(): OMX_CommandStateSet issued
04-04 23:11:24.704: E/OMX-VDEC-1080P(217): Current State 2, Expected State 1
04-04 23:11:24.704: E/OMX-VDEC-1080P(217): send_command_proxy(): Idle-->Loaded-Pending
04-04 23:11:24.704: E/OMX-VDEC-1080P(217): send_command: Command Processed
04-04 23:11:24.704: E/OMX-VDEC-1080P(217): ION: free: handle(0xEB8C3D00), len(2097152), fd(0x41)
04-04 23:11:24.704: E/OMXNodeInstance(217): OMX_FreeBuffer for buffer header 0x43f34670 successful
04-04 23:11:24.704: E/OMX-VDEC-1080P(217): ION: free: handle(0xDCAB0D00), len(2097152), fd(0x3f)
04-04 23:11:24.704: E/OMX-VDEC-1080P(217): ALL input buffers are freed/released
04-04 23:11:24.704: E/OMXNodeInstance(217): OMX_FreeBuffer for buffer header 0x43f34620 successful
04-04 23:11:24.704: E/OMX-VDEC-1080P(217): ION: free: handle(0xE4904BC0), len(368640), fd(0x46)
04-04 23:11:24.704: E/OMX-VDEC-1080P(217): ION: free: handle(0xD31AE040), len(73728), fd(0x44)
04-04 23:11:24.784: E/OMX-VDEC-1080P(217): ALL output buffers are freed/released
04-04 23:11:24.784: E/OMXNodeInstance(217): OMX_FreeBuffer for buffer header 0x43f348f8 successful
04-04 23:11:24.784: E/OMX-VDEC-1080P(217): OMX_CommandStateSet complete, m_state = 1
04-04 23:11:24.784: E/OMX-VDEC-1080P(217): Playback Ended - PASSED
04-04 23:11:24.784: E/OMX-VDEC-1080P(217): ALL output buffers are freed/released
04-04 23:11:24.784: E/OMX-VDEC-1080P(217): Error in ioctl read next msg
04-04 23:11:24.784: E/OMX-VDEC-1080P(217): omx_vdec: Async thread stop
04-04 23:11:24.784: E/OMX-VDEC-1080P(217): Close the driver instance
04-04 23:11:24.804: E/OMX-VDEC-1080P(217): omx_vdec::component_deinit() complete
04-04 23:11:24.804: E/OMX-VDEC-1080P(217): In OMX vdec Destructor
04-04 23:11:24.804: E/OMX-VDEC-1080P(217): omx_vdec: message thread stop
04-04 23:11:24.804: E/OMX-VDEC-1080P(217): Waiting on OMX Msg Thread exit
04-04 23:11:24.804: E/OMX-VDEC-1080P(217): Waiting on OMX Async Thread exit
04-04 23:11:24.804: E/OMX-VDEC-1080P(217): Exit OMX vdec Destructor

最佳答案

您尝试分配太大的缓冲区(10 * 10241 * 1024 = 104867840 字节)。即使 10241 * 1024 也太大了(10486784 字节)。尝试将其减小到 1024 * 1024 (1048576) 或更小;值得怀疑的是,您是否能够通过网络连接以足够快的速度传输数据,以至于需要这么大的缓冲区。

关于java - 上传文件超过300M时应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15820661/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com