日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

java上传的文件没有,java – 文件未上传到服务器

發(fā)布時(shí)間:2025/3/21 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java上传的文件没有,java – 文件未上传到服务器 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

我正在從我的

android應(yīng)用程序上傳音頻文件到server.Upload代碼正在我這邊運(yùn)行但是沒有文件沒有在服務(wù)器上傳.這是我正在使用的代碼.我還評(píng)論了代碼,文件正在上傳.here是代碼:

public void UploadFile(String path, String id) {

HttpURLConnection connection = null;

DataOutputStream outputStream = null;

String pathToOurFile = "" + path;

String urlServer = "http://txtapi.com/musicApp/uploadfile.php?fileId=" + id + "&sharedBy=" + sp.getString(CommonUtility.phone, CommonUtility.getPhoneNumber(ct));

String lineEnd = "\r\n";

String twoHyphens = "--";

String boundary = "*****";

int bytesRead, bytesAvailable, bufferSize;

byte[] buffer;

try {

FileInputStream fileInputStream = new FileInputStream(new File(pathToOurFile));

URL url = new URL(urlServer);

connection = (HttpURLConnection) url.openConnection();

// Allow Inputs & Outputs

connection.setDoInput(true);

connection.setDoOutput(true);

connection.setUseCaches(false);

// 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=\"fileId\";filename=\"" + path + "\"" + lineEnd);

outputStream.writeBytes(lineEnd);

bytesAvailable = fileInputStream.available();

// Read file

// bytesRead = fileInputStream.read(buffer, 0, bufferSize);//file is getting upload by this code

// int i =0;

// while (bytesRead > 0)

// {

// i++;

//

// outputStream.write(buffer, 0, bufferSize);

// bytesAvailable = fileInputStream.available();

// bufferSize = Math.min(bytesAvailable, maxBufferSize);

// bytesRead = fileInputStream.read(buffer, 0, bufferSize);

// }

buffer = new byte[1024];

int bufferLength = 0;

while ((bufferLength = fileInputStream.read(buffer)) > 0) {

//add the data in the buffer to the file in the file output stream (the file on the sd card

Log.i("bytes available ", "" + fileInputStream.available());

Log.i("buffer length", "" + bufferLength);

outputStream.write(buffer);

//add up the size so we know how much is downloaded

}

outputStream.writeBytes(lineEnd);

outputStream.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);

// Responses from the server (code and message)

fileInputStream.close();

outputStream.flush();

outputStream.close();

} catch (Exception ex) {

ex.printStackTrace();

BugSenseHandler.setLogging(true);

//Exception handling

Log.i("Inside catch of ", "Inside catch of upload ");

BugSenseHandler.sendException(ex);

} finally {

System.gc();

}

}

總結(jié)

以上是生活随笔為你收集整理的java上传的文件没有,java – 文件未上传到服务器的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。