Home > database >  How to use posturl upload file?
How to use posturl upload file?

Time:09-18

PB in POSTURL the parameters of the function call to upload data ls_arg only one parameter, but if there are files, how to upload the file? The file to read and String format, and other parameters are combined and translated into a BLOB? Or there are other ways to solve?

CodePudding user response:

refer to the original poster u013510134 response:
PB in POSTURL the parameters of the function call, only one parameter ls_arg to upload data, but if there are files, how to upload the file? The file to read and String format, and other parameters are combined and translated into a BLOB? Or there are other ways to solve?


Upload the binary file is a little trouble, give you a piece of code you consult


String ls_url ls_data, ls_args ls_header, ls_sql, ls_boundary
Blob lblb_args, lb_data
Long ll_cpu ll_i, ll_length
Int li_rc
Ls_url="http://localhost/PostUpdateBlob"
Ls_boundary="-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 7 db15a14291cce"//-- -- -- -- -- -- -- -- -- -- 7 db15a14291cce
"Ls_args +="-" + ls_boundary + "~ r ~ n
"Ls_args +='Content - Disposition: the form - data; Name="file"; Filename="aaa. Dat" ~ r ~ n '//name must be the file
Ls_args +='the content-type: application/octet - stream ~ r ~ n'
Ls_args +='~ r ~ n'

Lblb_args=Blob (ls_args EncodingUTF8!) + ab_data + Blob (' ~ r ~ n ~ r ~ n - '+' - ~ r ~ n + ls_boundary, EncodingUTF8!)
Ll_length=Len (lblb_args)
Ls_header="content-type: multipart/form - data; A boundary="+ ls_boundary + ~ r ~ n + & amp;
"The Content - Length:" + String (ll_length) + "~ r ~ n ~ r ~ n ~ r ~ n"
Li_rc=iinet_base. PostURL (ls_url lblb_args, ls_header, ii_httpPort, iir_msgbox)
If li_rc=1 then
Ls_data=https://bbs.csdn.net/topics/string (iir_msgbox ib_data EncodingUTF8!)
Return true
The else
Messagebox (' PostUrl error ', li_rc)
Return false
end if

CodePudding user response:

Cannot upload by parameters, the previous code is used to my pb12

CodePudding user response:

Thank PB in life, you said in the # 2 "cannot upload by parameters, what meaning be? Whether does the # 1 to not do?"
I am using version 10.5, iir_msgbox object, no ib_data attribute, this property in 12 version is?

CodePudding user response:

reference u013510134 reply: 3/f
thank PB in life, you said in the # 2 "cannot upload by parameters, what meaning be? Whether does the # 1 to not do?"
I am using version 10.5, iir_msgbox object, no ib_data attribute, this property in 12 version is?


Didn't mean that, can't be directly through the parameters to upload you wrote "POSTURL function call parameters in PB, only one parameter ls_arg to upload data,", must use the method of 1 #

CodePudding user response:

I am using version 10.5, iir_msgbox object, no ib_data attribute, this property in 12 version is?

Answer: ib_data is an instance variable defined in iir_msgbox, to define the

Blob ib_data

CodePudding user response:

The above requirements, has been friends with JAVA implementation side
The String url="http://localhost:8080/notary_sys/syncCertPic.html";
PostMethod PostMethod=new PostMethod (url);
HttpClient HttpClient=new HttpClient ();
BufferedInputStream bis=null;
Int connectTimeout=20000;
Int readTimeout=120000;
HttpConnectionManagerParams managerParams=httpClient. GetHttpConnectionManager (.) getParams ();
//sets the connection timeout time (in milliseconds)
ManagerParams. SetConnectionTimeout (connectTimeout);
//set the read data timeout time (in milliseconds)
ManagerParams. SetSoTimeout (readTimeout);
PostMethod. GetParams (.) setContentCharset (" utf-8 ");
Int the status;
The File image=new File (" E: \ \ imageUtils \ \ 1383384120430. PDF ");
InputStream is=null;
Try {
Is=new FileInputStream (image);
} the catch (FileNotFoundException e) {
//TODO Auto - generated the catch block,
e.printStackTrace();
}
ByteArrayOutputStream swapStream=new ByteArrayOutputStream ();
Byte [] buff=new byte [100].//buff to hold temporary data read cycle
Int rc=0;
Try {
While ((rc=is read (buff, 0, 100)) & gt; 0 {
SwapStream. Write (buff, 0, rc);
}
{} the catch (IOException e1)
//TODO Auto - generated the catch block,
e1.printStackTrace();
}
Byte [] in_b=swapStream. ToByteArray ();
Java. IO. ByteArrayInputStream bInput=new Java IO. ByteArrayInputStream (in_b);
Try {
PostMethod. SetRequestHeader (" the content-type ", "application/octet - stream");
RequestEntity re=new InputStreamRequestEntity (bInput);
PostMethod. SetRequestEntity (re);

NameValuePair params=new NameValuePair ();
Params. Elegantly-named setName (" years ");
Params. SetValue (" 2013 ");

NameValuePair params1=new NameValuePair ();
Params1. Elegantly-named setName (" certType ");
Params1. SetValue (" ");

NameValuePair params2=new NameValuePair ();
Params2. Elegantly-named setName (" certNo ");
Params2. SetValue (" 47321 ");

NameValuePair params3=new NameValuePair ();
Params3. Elegantly-named setName (" imageType ");
Params3. SetValue (" 0 ");

NameValuePair params4=new NameValuePair ();
FileIndex params4. Elegantly-named setName (" ");
Params4. SetValue (" 2 ");

PostMethod. SetQueryString (new NameValuePair [] {params, params1, params2 params3, params4});

Status=httpClient. ExecuteMethod (postMethod);
The bis=new BufferedInputStream (postMethod getResponseBodyAsStream ());
StringBuffer sb=new StringBuffer ();
int c;
While ((c=bis. Read ())!=1)
{
Sb. Append ((char) (c));
}
String resultStr=new String (sb. ToString (). GetBytes (" iso - 8859-1 "), "utf-8");

} the catch (Exception e) {
//TODO Auto - generated the catch block,
e.printStackTrace();
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related