當前位置:首頁 » 安卓系統 » android文件上傳伺服器

android文件上傳伺服器

發布時間: 2022-04-22 05:29:22

『壹』 使用android上傳圖片到伺服器,並且把圖片保存到伺服器的某個文件夾

有兩種方法,第一,把你的圖片轉成位元組流,然後用post方法把位元組流傳到服務端,然後服務端接收到位元組流之後,開啟一個線程把它重新壓縮成圖片,保存在某個文件夾下面。
第二,開啟一個線程,用socket直接把圖片放到stream中傳到服務端,服務端接收後保存到文件夾下。

『貳』 android中數據上傳到伺服器怎麼實現

伺服器端寫個servlet,然後在doPost()方法里處理客戶端上傳的文件,大概代碼: DiskFileItemFactory factory = new DiskFileItemFactory(); factory.setSizeThreshold(1024 * 1024); // 設置最多隻允許在內存中存儲的數據, 單位:位元組 factory.setRepository(cachepath); // 設置一旦文件大小超過設定值時數據存放的目錄 ServletFileUpload srvFileUpload = new ServletFileUpload(factory); srvFileUpload.setSizeMax(1024 * 1024 * 1024); // 設置允許用戶上傳文件大小, 單位:位元組 // 開始讀取上傳信息 List fileItems = null; try { fileItems = srvFileUpload.parseRequest(request); } catch (Exception e) { System.out.println("獲取上傳信息。。。。。。失敗"); } // 依次處理每個上傳的文件 Iterator iter = fileItems.iterator(); while (iter.hasNext()) { FileItem item = (FileItem) iter.next(); // 忽略其他不是文件域的所有表單信息 if (!item.isFormField()) { // 取出文件域的所有表單信息 } else { // 取出不是文件域的所有表單信息 } }

『叄』 Android 上傳圖片到伺服器

final Map<String, String> params = new HashMap<String, String>();
params.put("send_userId", String.valueOf(id));
params.put("send_email", address);
params.put("send_name", name);
params.put("receive_email", emails);

final Map<String, File> files = new HashMap<String, File>();
files.put("uploadfile", file);

final String request = UploadUtil.post(requestURL, params, files);

『肆』 Android上大文件傳輸到伺服器,最大能傳輸多大的文件

Android 上傳時, 雖然他的定義是long型的, 但是位元組長度還是會受到 Integer.Max的影響,所以上傳是多隻能傳 2.1G 的文件.

『伍』 android實現文件上傳的功能

我是這樣做的
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
intent.addCategory(Intent.CATEGORY_OPENABLE);
startActivityForResult(Intent.createChooser(intent, "請選擇一個要上傳的文件"), 1);
然後選擇文件後調用
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK) {
Uri uri = data.getData();
String url= uri.toString();


獲得路徑,根據路徑調用
public String convertCodeAndGetText(String str_filepath) {// 轉碼\
try {
File file1 = new File(str_filepath);
file_name = file1.getName();
FileInputStream in = new FileInputStream(file1);
byte[] buffer = new byte[(int) file1.length() + 100];
int length = in.read(buffer);
load = Base64.encodeToString(buffer, 0, length,
Base64.DEFAULT);
in.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

return load;
}
對文件進行編碼

『陸』 如何做一個能將文件上傳到區域網伺服器的軟體,適用於ANDROID系統

伺服器上共享一個目錄就可以了,客戶端用smb協議訪問網路目錄。目前已經有ES文件瀏覽器等軟體已經實現了此功能。
也有用ftp協議的。
你自己開發的話就比較隨意了,兩邊遵守同一個傳輸協議就行,當然服務端也能用vb來做

『柒』 android 視頻文件上傳到伺服器

android端:使用httpclient的multipart post提交數據到伺服器端;

伺服器端:普通解析上傳即可,與普通web開發處理上傳相同。

『捌』 android中如何上傳圖片到FTP伺服器

在安卓環境下可以使用,在java環境下也可以使用,已經在Java環境下實現了功能,然後移植到了安卓手機上,其它都是一樣的。

[java] view plain
package com.photo;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPReply;

public class FileTool {

/**
* Description: 向FTP伺服器上傳文件
*
* @param url
* FTP伺服器hostname
* @param port
* FTP伺服器埠
* @param username
* FTP登錄賬號
* @param password
* FTP登錄密碼
* @param path
* FTP伺服器保存目錄,是linux下的目錄形式,如/photo/
* @param filename
* 上傳到FTP伺服器上的文件名,是自己定義的名字,
* @param input
* 輸入流
* @return 成功返回true,否則返回false
*/
public static boolean uploadFile(String url, int port, String username,
String password, String path, String filename, InputStream input) {
boolean success = false;
FTPClient ftp = new FTPClient();

try {
int reply;
ftp.connect(url, port);// 連接FTP伺服器
// 如果採用默認埠,可以使用ftp.connect(url)的方式直接連接FTP伺服器
ftp.login(username, password);//登錄
reply = ftp.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
ftp.disconnect();
return success;
}
ftp.changeWorkingDirectory(path);
ftp.storeFile(filename, input);

input.close();
ftp.logout();
success = true;
} catch (IOException e) {
e.printStackTrace();
} finally {
if (ftp.isConnected()) {
try {
ftp.disconnect();
} catch (IOException ioe) {
}
}
}
return success;
}

// 測試
public static void main(String[] args) {

FileInputStream in = null ;
File dir = new File("G://pathnew");
File files[] = dir.listFiles();
if(dir.isDirectory()) {
for(int i=0;i<files.length;i++) {
try {
in = new FileInputStream(files[i]);
boolean flag = uploadFile("17.8.119.77", 21, "android", "android",
"/photo/", "412424123412341234_20130715120334_" + i + ".jpg", in);
System.out.println(flag);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}

}
}

以上為java代碼,下面是android代碼。

[java] view plain
package com.ftp;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

new uploadThread().start();
}

class uploadThread extends Thread {
@Override
public void run() {
FileInputStream in = null ;
File dir = new File("/mnt/sdcard/DCIM/Camera/test/");
File files[] = dir.listFiles();
if(dir.isDirectory()) {
for(int i=0;i<files.length;i++) {
try {
in = new FileInputStream(files[i]);
boolean flag = FileTool.uploadFile("17.8.119.77", 21, "android", "android",
"/", "412424123412341234_20130715120334_" + i + ".jpg", in);
System.out.println(flag);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
}
}
}

『玖』 android 如何把一個資料庫文件提交到伺服器上面去

json就和map的用法一樣,new一個JSONObject json=new JSONObject();
json.put("username", username);
json.put("password",password);
用httppclient這個類傳過去,post請求的話代碼比較多就不寫了,我說下get請求比如你的web項目名字是ServletTest,並且你在項目里寫個servlet類名字叫test。那麼沒有綁定域名的情況下url地址應該是http : // +localhost:8080/ ServletTest/test?msg= ( json.toString)。注意括弧內要在代碼實現。 然後在伺服器端收的信息就是{「username」:username , "password": password}格式的數據了。在你的test類裡面doGet(HttpRequest request , HttpResponse respone){
String msg=request.getParameter("msg");//就能得到{「username」:username , "passwor。。。。
然後JSONObject serverjson=new JSONObject(msg);
String name= serverjson.getString("username");
String password=serverjson.getString("password");
這樣就是封裝發送解析的過程
}.

『拾』 android怎麼上傳pdf文件到伺服器

掃描儀吧,掃描儀的輸出選擇裡面可以選擇輸出格式為pdf 呃,你沒有掃描儀,那有什麼其他工具呢?照相機?

熱點內容
明日之後怎麼實名認證安卓 發布:2024-04-19 13:35:55 瀏覽:935
數據加密解密演算法 發布:2024-04-19 13:25:52 瀏覽:944
安卓平板存儲空間不知道用在哪裡 發布:2024-04-19 12:58:57 瀏覽:764
出售lol腳本防封判幾年 發布:2024-04-19 12:45:14 瀏覽:187
安卓電視會員和平板哪個好 發布:2024-04-19 12:42:48 瀏覽:834
雲伺服器2m寬是多少 發布:2024-04-19 11:56:36 瀏覽:728
android層布局 發布:2024-04-19 11:52:13 瀏覽:771
1500元組裝伺服器電腦 發布:2024-04-19 11:47:25 瀏覽:469
qq改密碼怎麼改手機 發布:2024-04-19 11:39:17 瀏覽:969
電腦上如何看wifi密碼 發布:2024-04-19 11:34:14 瀏覽:416