netwebservice上傳圖片
Ⅰ 求教C#:WebService: 我想通過Webservice進行圖片的傳輸
這個網上一大把例子,我之前就在項目中做好了,需要的話私聊
Ⅱ android拍照+文字上傳到.net或webservice怎麼做
法/步驟
1
在eclipse上安裝好android開發環境,android調用webservice使用ksoap,本經驗使用的是ksoap2-android-assembly-2.6.4-jar-with-dependencies.jar
2
AndroidManifest.xml中需添加相應的許可權,例子:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.camera"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="9" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.camera.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Ⅲ ASP.NET WebService文件上傳,如果調用webservice的用戶量超大,並且存在同時調用,並且還是多文件上傳的
你好,是這樣的,webservice是專用來提供服務的,他可承受的壓力取決於兩個因素,連接頻率(或者是連接數量)和數據量大小。一般來說不是很大的系統的話即使是上傳大文件也不會對伺服器造成太大壓力。 實現分塊上傳其實並不是為了給伺服器減壓,它的主要目的是防止文件過大造成ASP頁面提交過期,而且通過分塊上傳可以做一些進度條,改善用戶體驗。
這里有一個問題你需要注意,如果你用webservice文件上傳實際上文件會在伺服器中間流轉兩次,第一次文件流通過表單發送到WEB伺服器上,然後你把這些文件在轉換成byte[]發送到webservice上。所以所用webservice上傳文件的最主要目的是網站資源分布式,即 ASP.net執行代碼和靜態資源放到不同伺服器上,實現用戶瀏覽時頁面HTTP請求的多伺服器分散。也可以便於以後WEB伺服器的擴充。
Ⅳ 我要傳一張圖片到服客戶端怎麼用webservice傳
string filePath = this.openFileDialog1.FileName;
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
BinaryWriter bw;
byte[] photo = br.ReadBytes((int)fs.Length);
fs = new FileStream("C:\\ok" + ".jpg", FileMode.OpenOrCreate, FileAccess.Write);
bw = new BinaryWriter(fs);
bw.Write(photo);
//byte[]轉成Base64String
String s_photo = Convert.ToBase64String(photo, System.Base64FormattingOptions.None);
br.Close();
fs.Close();
Ⅳ .net的webservice如何發布
你好,需要在你的Web.conf文件中添加如下代碼才可以在別的電腦訪問:
==》注意比對你的Config找到添加的位置:
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
</system.web>
</configuration>
Ⅵ android拍照+文字上傳到.net或webservice怎麼做
方法/步驟1
在eclipse上安裝好android開發環境,android調用webservice使用ksoap,本經驗使用的是ksoap2-android-assembly-2.6.4-jar-with-dependencies.jar
2
AndroidManifest.xml中需添加相應的許可權,例子:
<?xmlversion="1.0"encoding="utf-8"?>
<manifestxmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.camera"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="9"/>
<uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permissionandroid:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<uses-permissionandroid:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name="com.example.camera.MainActivity"
android:label="@string/app_name">
<intent-filter>
<actionandroid:name="android.intent.action.MAIN"/>
<categoryandroid:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
3
activity_main.xml文件代碼
<?xmlversion="1.0"encoding="utf-8"?>
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<Button
android:id="@+id/button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="點擊啟動相機"/>
<Button
android:id="@+id/savePic"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="保存圖片到伺服器"/>
<TextView
android:id="@+id/textView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<ImageView
android:id="@+id/imageView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#999999"/>
</LinearLayout>
4
MainActivity具體代碼
packagecom.example.camera;
importjava.io.ByteArrayOutputStream;
importjava.io.File;
importjava.io.FileInputStream;
importjava.io.FileNotFoundException;
importjava.io.FileOutputStream;
importjava.io.IOException;
importorg.kobjects.base64.Base64;
importorg.ksoap2.SoapEnvelope;
importorg.ksoap2.serialization.SoapObject;
importorg.ksoap2.serialization.SoapSerializationEnvelope;
importorg.ksoap2.transport.HttpTransportSE;
importandroid.app.Activity;
importandroid.content.Intent;
importandroid.graphics.Bitmap;
importandroid.os.Bundle;
importandroid.os.Environment;
importandroid.provider.MediaStore;
importandroid.util.Log;
importandroid.view.View;
importandroid.view.View.OnClickListener;
importandroid.widget.Button;
importandroid.widget.ImageView;
importandroid.widget.TextView;
{
TextViewtv=null;
StringfileName="/sdcard/myImage/my.jpg";//圖片保存sd地址
Stringnamespace="http://webservice.service.com";//命名空間
Stringurl="http://192.168.200.19:8080/Web/webservices/Portal";//對應的url
StringmethodName="uploadImage";//webservice方法
@Override
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv=(TextView)findViewById(R.id.textView);
//啟用相機按鈕
Buttonbutton=(Button)findViewById(R.id.button);
button.setOnClickListener(newOnClickListener(){
@Override
publicvoidonClick(Viewv){
Intentintent=newIntent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent,1);
}
});
//保存圖片到伺服器按鈕(通過webservice實現)
ButtonsaveButton=(Button)findViewById(R.id.savePic);
saveButton.setOnClickListener(newOnClickListener(){
@Override
publicvoidonClick(Viewv){
testUpload();
}
});
}
/**
*拍照完成後,回掉的方法
*/
@Override
protectedvoidonActivityResult(intrequestCode,intresultCode,Intentdata){
super.onActivityResult(requestCode,resultCode,data);
if(resultCode==Activity.RESULT_OK){
StringsdStatus=Environment.getExternalStorageState();
if(!sdStatus.equals(Environment.MEDIA_MOUNTED)){//檢測sd是否可用
Log.v("TestFile",
"SDcardisnotavaiable/writeablerightnow.");
return;
}
Bundlebundle=data.getExtras();
Bitmapbitmap=(Bitmap)bundle.get("data");//獲取相機返回的數據,並轉換為Bitmap圖片格式
FileOutputStreamb=null;
Filefile=newFile("/sdcard/myImage/");
file.mkdirs();//創建文件夾
try{
b=newFileOutputStream(fileName);
bitmap.compress(Bitmap.CompressFormat.JPEG,100,b);//把數據寫入文件
}catch(FileNotFoundExceptione){
e.printStackTrace();
}finally{
try{
b.flush();
b.close();
}catch(IOExceptione){
e.printStackTrace();
}
}
((ImageView)findViewById(R.id.imageView)).setImageBitmap(bitmap);//將圖片顯示在ImageView里
}
}
/**
*圖片上傳方法
*
*1.把圖片信息通過Base64轉換成字元串
*2.調用connectWebService方法實現上傳
*/
privatevoidtestUpload(){
try{
FileInputStreamfis=newFileInputStream(fileName);
ByteArrayOutputStreambaos=newByteArrayOutputStream();
byte[]buffer=newbyte[1024];
intcount=0;
while((count=fis.read(buffer))>=0){
baos.write(buffer,0,count);
}
StringuploadBuffer=newString(Base64.encode(baos.toByteArray()));//進行Base64編碼
connectWebService(uploadBuffer);
Log.i("connectWebService","start");
fis.close();
}catch(Exceptione){
e.printStackTrace();
}
}
/**
*通過webservice實現圖片上傳
*
*@paramimageBuffer
*/
privatevoidconnectWebService(StringimageBuffer){
//以下就是調用過程了,不明白的話請看相關webservice文檔
SoapObjectsoapObject=newSoapObject(namespace,methodName);
soapObject.addProperty("filename","my.jpg");//參數1圖片名
soapObject.addProperty("image",imageBuffer);//參數2圖片字元串
=newSoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet=false;
envelope.setOutputSoapObject(soapObject);
=newHttpTransportSE(url);
try{
httpTranstation.call(namespace,envelope);
Objectresult=envelope.getResponse();
Log.i("connectWebService",result.toString());
tv.setText(result.toString());
}catch(Exceptione){
e.printStackTrace();
tv.setText(e.getStackTrace().toString());
}
}
}
5
服務端webservice方法(cxf)
publicStringuploadImage(Stringfilename,Stringimage){
FileOutputStreamfos=null;
try{
StringtoDir="D:\work\image";//存儲路徑
byte[]buffer=newBASE64Decoder().decodeBuffer(image);//對android傳過來的圖片字元串進行解碼
FiledestDir=newFile(toDir);
if(!destDir.exists()){
destDir.mkdir();
}
fos=newFileOutputStream(newFile(destDir,filename));//保存圖片
fos.write(buffer);
fos.flush();
fos.close();
return"上傳圖片成功!"+"圖片路徑為:"+toDir;
}catch(Exceptione){
e.printStackTrace();
}
return"上傳圖片失敗!";
}
操作步驟
(1)點擊「點擊啟動相機」按鈕,回到拍照模式下,拍照完成,回到初始界面,顯示剛拍的照片
(2)點擊「保存照片到伺服器」按鈕,通過webservice把照片保存到伺服器中,TextView顯示保存信息。
Ⅶ 在delPhi中怎麼通過webservice上傳文件,比較
您好,很高興能幫助您
把上傳的圖片進行編碼(base64),數據傳輸到伺服器端後再進行解碼生成圖片
你的採納是我前進的動力,
記得好評和採納,答題不易,互相幫助,
Ⅷ android拍照+文字上傳到.net或webservice怎麼做
<%@ WebHandler Language="C#" Class="uploadHandler" %>
using
System;
using System.Web;
using System.IO;
public class
uploadHandler : IHttpHandler {
public void ProcessRequest
(HttpContext context) {
context.Response.ContentType =
"text/plain";
context.Response.Charset = "utf-8";
string
suser=context.Request.QueryString["puser"]; //頁面傳過來的用戶id
HttpPostedFile file = context.Request.Files["Filedata"];//頁面傳過來的文件
string uploadPath = HttpContext.Current.Server.MapPath("/upload/pic/idcard")
+ "\\"; //身份證文件夾
string filename = file.FileName;
int
i = filename.LastIndexOf(".");
string fileExt =
filename.Substring(i);
//DateTime datenow = DateTime.Now;
//string datestring = datenow.ToString("yyyyMMdd");
//string
sizestring = file.ContentLength.ToString();
if (file !=
null)
{
if (!Directory.Exists(uploadPath))
{
Directory.CreateDirectory(uploadPath);
}
string uploadoripath = uploadPath + suser + fileExt;
file.SaveAs(uploadoripath);//保存
context.Response.Write("http://xxxxxxx/pic/idcard/"+suser + fileExt);
//返回圖片地址
//context.Response.Write(@context.Request["folder"].ToString()+datestring +
sizestring + fileExt);
}
else
{
context.Response.Write("0");
}
}
public bool
IsReusable {
get {
return false;
}
}
}
Ⅸ android如何將圖片上傳到asp.net編寫的webservice
利用二進制流來傳
asp.net編寫web service時候,給個參數byte[],然後把這個byte[]存儲成圖片。用FileStream就可以。
android在調用時將需要上傳的圖片轉換為byte[]就可以了。