post上傳圖片到伺服器
A. java 怎麼根據httpPost 和httpClient 等,傳圖片到伺服器!
使用Apache提供的HttpClient組件可以實現。其實傳圖片就是用POST方式向伺服器發送數據。
B. 使用apicloud的getPicture模塊 選擇圖片怎麼上傳伺服器
實現思路:
1、api.getPicture獲取到本地圖片的路徑
2、api.ajax使用post方式上傳這張圖片,
3、你的伺服器接收完圖片後返回這張圖片在你伺服器上的地址。
以上涉及到的api請到文檔區域參考端api下的getPicture以及ajax的使用,伺服器如何處理接收圖片然後返回圖片地址,請咨詢相應語言伺服器開發的專業人士。
C. c# post怎麼同時上傳圖片流和文本流的
你所說的,不論是圖片還是文本,其實就是文件上傳。
關於文件上傳,我之前見過的一個,微軟的伺服器,是通過POST數據,一塊一塊上傳數據的。
要是想參考相關的代碼,你可以直接去搜:
insertskydrivefiles
找到我在google code上面公開發布的代碼,然後再參考:
【整理】google code簡介和用法
去在線瀏覽對應的代碼,其中在
在InsertSkydriveFiles/skydrive.cs中,有函數:
public bool uploadFile(string fileAbsAddr, bool autoHandleFilename, string parentId, bool isOverwrite, string uploadFileName, out string resourceId, out string errMsg)
其中有具體實現的。
而關於如何分析上傳文件的邏輯,可以參考:
【整理】關於抓取網頁,分析網頁內容,模擬登陸網站的邏輯/流程和注意事項
(此處不給貼地址,自己搜相關的標題,即可找到這些帖子,實在找不到帖子,站內發信給我,我再告訴你)
D. 安卓關於上傳文件到伺服器,該怎麼處理
如果是圖片,一般旦枝基我們採用將圖片轉換為base64編碼的字模謹符串,然後向伺服器post,搭坦伺服器接收後,再解碼base64字元串為圖片保存,從而實現上傳。貌似從Android上上傳圖片以外的其它文件的需求也比較小吧?
E. 用php如何把一些文件和圖片上傳到另一指定的伺服器
一個實例:
首先,在自己台式機和筆記本上都開通了ftp,這個不會的同學可以網上查serv-u,相關教程肯定不少的。
然後在台式機本地做了個測試:
$ftp_server = "192.168.1.100";
$ftp_user_name = "laohu";
$ftp_user_pass = "123456";
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server");
$file = 'test.txt';
$remote_file = '/test/a.txt';
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
if (ftp_put($conn_id, $remote_file, $file, FTP_BINARY)) {
echo "文件移動成功\n";
} else {
echo "移動失敗\n";
}
ftp_close($conn_id);
運行後:文件移動成功。
要的就是這個效果了,之後用台式機做程序伺服器,上傳附件時全用ftp方法上傳至筆記本上,筆記本ip是105,相應代碼如下:
if (is_uploaded_file($_FILES['uploadfile']['tmp_name'])) {
$ftp_server = "192.168.1.105";
$ftp_user_name = "lesley";
$ftp_user_pass = "123456";
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server");
$file = $_FILES['uploadfile']['tmp_name'];
$remote_file = '/test/'.$_FILES['uploadfile']['name'];
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
if (ftp_put($conn_id, $remote_file, $file, FTP_BINARY)) {
echo "文件:".$_FILES['uploadfile']['name']."上傳成功\n";
} else {
echo "上傳失敗\n";
}
ftp_close($conn_id);
}
對應的前台頁面代碼:
<form action="uploadfile.php" method="post" enctype="multipart/form-data">
<input type="file" name="uploadfile" id="uploadfile" />
<input type="submit" name="submit" value="submit" />
</form>
運行後確實成功。
需要注意:
在用ftp_put方法時,第四個參數傳送模式,需要用FTP_BINARY(二進制模式),用FTP_ASCII(文本模式)時,圖片能上傳但無法顯示,其他文件重命名、中文亂碼解決、上傳許可權控制等,就不在此提及了。
F. java 中如何向伺服器上傳圖片
我們使用一些已有的組件幫助我們實現這種上傳功能。
常用的上傳組件:
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);
}
G. 高分:VB 調用INET用POST方式發圖片到伺服器。
winsock 可以UDP協議啊 呵呵 圖片是要轉為一個緩存的二進制文件賀蘆 在發送 然後取出
將其內容全部讀入一個byte類型的數組中,客戶端代碼如下:
dimmyfile()asbyte
dimpositionaslong
open"filename"forbinaryas#1
position=0
dowhilenoteof(1)
position=positon 1
redimpreservemyfile(1toposition)
get#1,,myfile(position)
loop
close#1
再向遠程機傳送這個位元組數組
sckserver.SendDatamyfile
遠程機收到這個數組之後,再以二進制鍵拍鍵文件的方式打開一個新目標文件,將數組內容寫稿巧入這個新打開的文件,如果是bmp圖片就將其放入picture圖片框中,如果是wav文件,就播放。這樣,區域網中的兩個人就可以通過語言、圖片、文字來交流了。
服務端代碼如下:
Privatesubsckconnect_DataArrival(byvalbytestotalaslong)
dimreceivefile(1tobytestotal)asbyte
sckconnect.GetDatareceivefile,vbarray vbbyte
'告訴Winsock控制項收到的是位元組數組類型的數據
open"c:\temp\文件名"forbinaryas#1
forI=1tobytestotal
put#1,,remotearray(I)
nextI
clost#1
end sub
H. php 編寫 實現上傳圖片至伺服器的函數
php上傳圖片客戶端和伺服器端實現方法分享給大家供大家參考。具體如下:
前台表單代碼
<form name="form1" method="post" action="admin_upfile.php" enctype="multipart/form-data">
<input type="file" name="pic">
<input type="submit" name="Submit" value="開始上傳" class="button">
</form>
後端php代碼
<?php
//這里上傳 $upsize判斷上傳文件的大小
$uppath = "/attached/"; //文件上傳路徑
//轉換根目錄的路徑
if (strpos($uppath, "/") == 0)
{
$i = 0;
$thpath = $_SERVER["SCRIPT_NAME"];
$thpath = substr($thpath, 1, strlen($thpath));
while (strripos($thpath, "/") !== false)
{
$thpath = substr($thpath, strpos($thpath, "/") + 1, strlen($thpath));
$i = ++$i;
}
$pp = "";
for ($j = 0; $j < $i; ++$j)
{
$pp .= "../";
}
$uppaths = $pp . substr($uppath, 1, strlen($thpath));
}
$filename = date("y-m-d");
if (is_dir($uppaths . $filename) != TRUE)
mkdir($uppaths . $filename, 0777);
$f = $_FILES['pic'];
if ($f["type"] != "image/gif" && $f["type"] != "image/pjpeg" && $f["type"] != "image/jpeg" && $f["type"] != "image/x-png")
{
echo "<script>alert('只能上傳圖片格式的文件');window.close()</script>";
return false;
}
//獲得文件擴展名
$temp_arr = explode(".", $f["name"]);
$file_ext = array_pop($temp_arr);
$file_ext = trim($file_ext);
$file_ext = strtolower($file_ext);
//新文件名
$new_file_name = md5(date("YmdHis")) . '.' . $file_ext;
echo $dest = $uppaths . $filename . "/" . date("ymdhis") . "_" .
$new_file_name; //設置文件名為日期加上文件名避免重復 上傳目錄
echo $dest1 = $uppath . $filename . "/" . date("ymdhis") . "_" .
$new_file_name; //設置文件名為日期加上文件名避免重復
$r = move_uploaded_file($f['tmp_name'], $dest);
?>
I. ios 端可以直接用post 提交一個file類型文件到服務端嗎
首相將你的圖片轉換為data格式,之後你可以使用AFNetWorking中
[manager POST:(NSString * __nonnull) parameters:(nullable id) constructingBodyWithBlock:^nullable void(id<AFMultipartFormData> __nonnull) {
[formData appendPartWithFileData:@"你圖片的data" name:@"我用的是圖片上傳以後的名字" fileName:@"上傳以後的圖片名字" mimeType:@"image/jpeg"];
} success:^nullable void(AFHTTPRequestOperation * __nonnull, id __nonnull) {
<#code#>
} failure:^nullable void(AFHTTPRequestOperation * __nonnull, NSError * __nonnull) {
<#code#>
}]
這個方法,希望有幫助
J. 使用android上傳圖片到伺服器,並且把圖片保存到伺服器的某個文件夾里
有兩種方法,第一,把你的圖片轉成位元組流,然後用post方法把位元組流傳到服務端,然後服務端接收到位元組流之後,開啟一個線程把它重新壓縮成圖片,保存在某個文件夾下面。
第二,開啟一個線程,用socket直接把圖片放到stream中傳到服務端,服務端接收後保存到文件夾下。