當前位置:首頁 » 雲伺服器 » 怎麼把圖片傳到伺服器

怎麼把圖片傳到伺服器

發布時間: 2023-09-20 09:57:01

❶ 如何上傳圖片到圖片伺服器

使用一些已有的組件幫助我們實現這種上傳功能。 常用的上傳組件: Apache 的 Commons FileUpload JavaZoom的UploadBean jspSmartUpload 以下,以FileUpload為例講解 1、在jsp端 <form id="form1" name="form1" method="post" action="servlet/fileServlet" enctype="multipart/form-data"> 要注意enctype="multipart/form-data" 然後只需要放置一個file控制項,並執行submit操作即可 <input name="file" type="file" size="20" > <input type="submit" name="submit" value="提交" > 2、web端 核心代碼如下: public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); DiskFileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); try { List items = upload.parseRequest(request); Iterator itr = items.iterator(); while (itr.hasNext()) { FileItem item = (FileItem) itr.next(); if (item.isFormField()) { System.out.println("表單參數名:" + item.getFieldName() + ",表單參數值:" + item.getString("UTF-8")); } else { if (item.getName() != null && !item.getName().equals("")) { System.out.println("上傳文件的大小:" + item.getSize()); System.out.println("上傳文件的類型:" + item.getContentType()); System.out.println("上傳文件的名稱:" + item.getName()); File tempFile = new File(item.getName()); File file = new File(sc.getRealPath("/") + savePath, tempFile.getName()); item.write(file); request.setAttribute("upload.message", "上傳文件成功!"); }else{ request.setAttribute("upload.message", "沒有選擇上傳文件!"); } } } }catch(FileUploadException e){ e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); request.setAttribute("upload.message", "上傳文件失敗!"); } request.getRequestDispatcher("/uploadResult.jsp").forward(request, response); }

❷ 向伺服器上傳圖片

你要是沒有FTP上傳軟畢旅激件的話你可以如下操作:
1.打開瀏覽器,在地址欄輸入主機手襪地鎮虛址.
2.連接上後輸入用戶名和密碼.
3.把網頁文件復制到你打開的伺服器上去

❸ 將本地圖片通過地址上傳至伺服器,怎麼操作一次行上傳三張圖片,如圖:

你好朋友;
在那個圖片文件路徑中內;
你輸入你電腦中內的圖片的;
完整路徑;必須是完整路徑;
比如C:\123\456\我愛你.jpg;
然後點擊上傳按鈕就能上傳了;
而你若是不想輸入完整路徑的話;
那就點擊那個瀏覽按鈕;然後你;
在你電腦中內找到你想上傳的圖片;
點擊右下角打開按鈕;然後再按上傳就行了;
朋友這個不難;很簡單的;特別容易操作

❹ 本地電腦的圖片怎麼上傳到伺服器

如果你是通過後台,打開伺服器,然後把文件拖進去~~~ 如果你是指上傳到網站 網盤等地方。點擊上傳,然後選擇圖片,然後確定。如果沒有上傳這個選項,則上傳不了。

❺ android怎樣上傳圖片到伺服器

界面很簡單,點擊 【選擇圖片】,從圖庫里選擇圖片,顯示到下面的imageview里,點擊上傳,就會上傳到指定的伺服器

布局文件:

?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="選擇圖片"
android:id="@+id/selectImage"
/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="上傳圖片"
android:id="@+id/uploadImage"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
/>
</LinearLayout>

Upload Activity:
?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105

public class Upload extends Activity implements OnClickListener {
private static String requestURL = "http://192.168.1.212:8011/pd/upload/fileUpload.do";
private Button selectImage, uploadImage;
private ImageView imageView;

private String picPath = null;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.upload);

selectImage = (Button) this.findViewById(R.id.selectImage);
uploadImage = (Button) this.findViewById(R.id.uploadImage);
selectImage.setOnClickListener(this);
uploadImage.setOnClickListener(this);

imageView = (ImageView) this.findViewById(R.id.imageView);

}

@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.selectImage:
/***
* 這個是調用android內置的intent,來過濾圖片文件 ,同時也可以過濾其他的
*/
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(intent, 1);
break;
case R.id.uploadImage:
if (picPath == null) {

Toast.makeText(Upload.this, "請選擇圖片!", 1000).show();
} else {
final File file = new File(picPath);

if (file != null) {
String request = UploadUtil.uploadFile(file, requestURL);
uploadImage.setText(request);
}
}
break;
default:
break;
}
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK) {
/**
* 當選擇的圖片不為空的話,在獲取到圖片的途徑
*/
Uri uri = data.getData();
Log.e(TAG, "uri = " + uri);
try {
String[] pojo = { MediaStore.Images.Media.DATA };

Cursor cursor = managedQuery(uri, pojo, null, null, null);
if (cursor != null) {
ContentResolver cr = this.getContentResolver();
int colunm_index = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
String path = cursor.getString(colunm_index);
/***
* 這里加這樣一個判斷主要是為了第三方的軟體選擇,比如:使用第三方的文件管理器的話,你選擇的文件就不一定是圖片了,
* 這樣的話,我們判斷文件的後綴名 如果是圖片格式的話,那麼才可以
*/
if (path.endsWith("jpg") || path.endsWith("png")) {
picPath = path;
Bitmap bitmap = BitmapFactory.decodeStream(cr
.openInputStream(uri));
imageView.setImageBitmap(bitmap);
} else {
alert();
}
} else {
alert();
}

} catch (Exception e) {
}
}

super.onActivityResult(requestCode, resultCode, data);
}

private void alert() {
Dialog dialog = new AlertDialog.Builder(this).setTitle("提示")
.setMessage("您選擇的不是有效的圖片")
.setPositiveButton("確定", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
picPath = null;
}
}).create();
dialog.show();
}

}

這個才是重點 UploadUtil:
?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89

public class UploadUtil {
private static final String TAG = "uploadFile";
private static final int TIME_OUT = 10 * 1000; // 超時時間
private static final String CHARSET = "utf-8"; // 設置編碼
/**
* 上傳文件到伺服器
* @param file 需要上傳的文件
* @param RequestURL 請求的rul
* @return 返回響應的內容
*/
public static int uploadFile(File file, String RequestURL) {
int res=0;
String result = null;
String BOUNDARY = UUID.randomUUID().toString(); // 邊界標識 隨機生成
String PREFIX = "--", LINE_END = "\r\n";
String CONTENT_TYPE = "multipart/form-data"; // 內容類型

try {
URL url = new URL(RequestURL);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(TIME_OUT);
conn.setConnectTimeout(TIME_OUT);
conn.setDoInput(true); // 允許輸入流
conn.setDoOutput(true); // 允許輸出流
conn.setUseCaches(false); // 不允許使用緩存
conn.setRequestMethod("POST"); // 請求方式
conn.setRequestProperty("Charset", CHARSET); // 設置編碼
conn.setRequestProperty("connection", "keep-alive");
conn.setRequestProperty("Content-Type", CONTENT_TYPE + ";boundary="+ BOUNDARY);

if (file != null) {
/**
* 當文件不為空時執行上傳
*/
DataOutputStream dos = new DataOutputStream(conn.getOutputStream());
StringBuffer sb = new StringBuffer();
sb.append(PREFIX);
sb.append(BOUNDARY);
sb.append(LINE_END);
/**
* 這里重點注意: name裡面的值為伺服器端需要key 只有這個key 才可以得到對應的文件
* filename是文件的名字,包含後綴名
*/

sb.append("Content-Disposition: form-data; name=\"file\"; filename=\""
+ file.getName() + "\"" + LINE_END);
sb.append("Content-Type: application/octet-stream; charset="
+ CHARSET + LINE_END);
sb.append(LINE_END);
dos.write(sb.toString().getBytes());
InputStream is = new FileInputStream(file);
byte[] bytes = new byte[1024];
int len = 0;
while ((len = is.read(bytes)) != -1) {
dos.write(bytes, 0, len);
}
is.close();
dos.write(LINE_END.getBytes());
byte[] end_data = (PREFIX + BOUNDARY + PREFIX + LINE_END)
.getBytes();
dos.write(end_data);
dos.flush();
/**
* 獲取響應碼 200=成功 當響應成功,獲取響應的流
*/
res = conn.getResponseCode();
Log.e(TAG, "response code:" + res);
if (res == 200) {
Log.e(TAG, "request success");
InputStream input = conn.getInputStream();
StringBuffer sb1 = new StringBuffer();
int ss;
while ((ss = input.read()) != -1) {
sb1.append((char) ss);
}
result = sb1.toString();
Log.e(TAG, "result : " + result);
} else {
Log.e(TAG, "request error");
}
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return res;
}
}

❻ 如何實現上傳的圖片上傳到其他的伺服器上

先要有對方伺服器的上傳帳號和密碼,然後用FTP等軟體連接到對方的伺服器,然後通過FTP等軟體上傳圖片即可。

❼ uniapp上傳圖片至伺服器,獲得在線圖片鏈接預覽(實戰)

功能需求:
前端選擇本地文件,將選擇好的文件顯示在界面上進行預覽,可同時選擇四張進行預覽。

思路如下:
前端選擇本地的png、jpg、等格式的圖片,將圖片以二進制的形式傳到後端伺服器,後端對二進制圖片進行處理,返回給前端一個伺服器鏈接在線圖片,在瀏覽器就可以打開鏈接訪問的那種。然後前端將這個圖片鏈接渲染在頁面進行預覽。

首先
我們看一下uniapp的官方文檔:
https://uniapp.dcloud.io/api/media/image?id=chooseimage

大概是這樣的
先寫一個模擬的demo
1:首先我是是用了colorUI的框架,在項目裡面引入

在page底下的vue文件引入

這樣一來,就不需要寫什麼樣式了,直接使用寫好的就行了。

效果是這樣的
每次選完圖片之後顯示在頁面上,我這里設置了最多可以選擇四張,圖片鏈接使用了臨時的blob,接下來就要使用後端小夥伴給的介面,將自己本地的二進制文件傳給他了。

在 chooseImage 選擇好圖片之後,寫一個成功的回調函數,在回到函數裡面添加一個圖片上傳的方法uploadFile,在方法裡面添加url,等參數。

若是請求成功
則返回一個圖片鏈接

添加介面之後 的,demo如下:

❽ 怎樣將圖片上傳到伺服器

工具/原料 FlashFXP VPN 文件夾步驟/方法 首先建立一個文件夾,把當天需要上傳的圖片存放到同一個文件夾,這樣不會和以前的圖片混淆一起難以辨認。然後就是連接到VPN,輸入VPN用戶名以及密碼,連接成功。打開FlashFXP,這個工具是上傳圖片的直接工具,首先連接到伺服器,點擊圓圈箭頭處的連接圖標,輸入連接類型、用戶名、密碼,連接成功。在FlashFXP工具的左欄的圓圈處打開開始創建的新文件夾,在FlashFXP工具的左欄的圓圈處打開一個新文件夾,這個很重要,最好是每天上傳圖片到伺服器中建立一個新的文件夾。將要上傳的圖片直接復制、粘貼到左欄框內,點擊滑鼠右鍵彈出的傳輸指令,然後上傳到伺服器成功。圖片上次伺服器已成功,然後就可以用代碼的格式編輯到文章中。注意事項 最好是每天上傳圖片到伺服器中建立一個新的文件夾。文件夾不要隨便更改其初始位置。圖片修改成較容易記的名稱,因為在插入圖片時要用源代碼的形式輸入圖片名稱。 更多精彩電腦信息,請登錄:中國高速網-IT頻道。

❾ 圖片怎麼上傳到tomcat伺服器,tomcat伺服器如何構建

你可以在系統裡面做一個上傳的功能,然後就能把圖片上傳到tomcat伺服器了啊。
tomcat伺服器不用構建。直接下載下來就能用。

熱點內容
極坐標圖編程 發布:2025-03-06 01:52:23 瀏覽:304
centos訪問網頁 發布:2025-03-06 01:51:18 瀏覽:970
海康威視華為雲伺服器 發布:2025-03-06 01:36:20 瀏覽:701
安卓手機怎麼把三張圖片拼在一起 發布:2025-03-06 01:31:50 瀏覽:320
文件夾刪除不了許可權 發布:2025-03-06 01:28:06 瀏覽:302
如何上傳swf 發布:2025-03-06 01:18:22 瀏覽:366
安卓機有什麼好玩的游戲 發布:2025-03-06 01:15:47 瀏覽:569
外鍵約束sql 發布:2025-03-06 01:07:53 瀏覽:64
魯大師代理伺服器如何設置 發布:2025-03-06 01:07:52 瀏覽:139
sqldescribe 發布:2025-03-06 00:57:17 瀏覽:492