Public void doUploadFile () throws the Exception
{
The String file="E:/044160004044 JPG";
String bh="430600100063";
String sj="2017-09-02 11:07:23";
ByteArrayOutputStream bos=new ByteArrayOutputStream ();
BufferedInputStream bis=new BufferedInputStream (new FileInputStream (file));
Int len.
While ((len=bis. Read ()) & gt; 1) {bos. Write (len); }
Byte fileData []=bos. ToByteArray ();
Int tpsize1=fileData. Length;
String urlstr="HTTP://http://127.0.0.1:8080/uploadFile.tfc? Method=savePicture& Bh="+ bh.
Urlstr +="& amp; Sj="+ sj.
URL the URL=new URL (urlstr);
HttpURLConnection huc=(HttpURLConnection) url. OpenConnection ();
Huc. SetRequestProperty (" the content-type ", "text/HTML");
Huc. SetRequestProperty (" the content-type ", "application/x - WWW - form - urlencoded; charset=utf-8");
Huc. SetDoOutput (true);
Huc. SetDoInput (true);
Huc. SetRequestMethod (" POST ");
Huc. SetConnectTimeout (500000);
OutputStream pw=huc. GetOutputStream ();
Pw. Write (fileData);
Pw. Flush ();
pw.close();
BufferedReader br=new BufferedReader (new InputStreamReader (huc. GetInputStream ()));
The String content="";
The String line=br. ReadLine ();
While (the line!=null)
{
The content=content + line;
The line=br. ReadLine ();
}
br.close();
}
How do the above code written in Delphi, I use Idhttp controls, picture is the copy of transfer will not come!
CodePudding user response:
The following was written by myself, images have been preach not upThe filename: ImagePath +='4035-367883-1. JPG';
The RequestURL: UploadPic +='? Method=savePicture& Bh=340800100024 & amp; Sj=2017-09-04 08:36:05 ';
Try
Ms:=TMemoryStream. Create;
Ms. LoadFromFile (filename);
Ms. SaveToStream (msa);
Except,
On e: the exception do
The begin
Memo1. Lines. The add (FormatDateTime (' yyyy - - dd hh: mm nn: ss, z ', now) + ': convert pictures out wrong:' + e.m essage);
end;
end;
IdHTTP:=TIdHTTP. Create (nil);
IdHTTP. ReadTimeout:=10000;
IdHTTP. AllowCookies:=True;
IdHTTP. Request. ContentType:='application/x - WWW - form - urlencoded; Charset=utf-8 ';//application/x - WWW - form - urlencoded
IdHTTP. HTTPOptions:=[hoForceEncodeParams];
IdHTTP. Request. Accept:='text/HTML, image/GIF image/jpeg, *; Q=2, */*; Q=. 2 ';
IdHTTP. Request. UserAgent:='Mozilla/3.0 (compatible; Indy Library) ';
Idhttp. Request. ContentType:='keep - the alive;
Idhttp. Request. CacheControl:='no - cache;
Idhttp. Request. Pragma:='no - cache;
Idhttp. Request. ContentLength:=Ms. Size;
Idhttp. Request. Host: ServerIP=+ + ServerPort ':';
Try
ResultUploadPic:=IdHTTP. Post (TIdURI URLEncode (RequestURL), msa);
Except,
On e: the exception do
The begin
Memo1. Lines. The add (FormatDateTime (' yyyy - - dd hh: mm nn: ss, z ', now) + ': submit pictures failure: + e.m essage);
end;
end;
IdHTTP. Free;
Freeandnil (ms).
Freeandnil (MSB);
CodePudding user response:
Inflow of MS image file to read, but did not see MS upload code,CodePudding user response: