delphi通过idhttp给springmvc上传文件

delphi端: 

var
    MutPartForm: TIdMultiPartFormDataStream;
    response: string;
    FHttp: Tidhttp;
begin
    FHttp := Tidhttp.Create(nil);
    FHttp.HandleRedirects := true;
    FHttp.AllowCookies := true;

    MutPartForm := TIdMultiPartFormDataStream.Create;
    MutPartForm.AddFormField('act', 'upload');
    MutPartForm.AddFormField('upcount', '1');
    MutPartForm.AddFormField('filepath', 'data');
    MutPartForm.AddFormField('databaseName', 'swgl');
    MutPartForm.AddFormField('billCode', '1DD-2020-08-01-0004');
   // MutPartForm.AddFormField('file1', 'filename="D:\exportPDF\1CG-2020-08-26-0001.pdf"');
    MutPartForm.AddFormField('Submit', 'Submit');
    MutPartForm.AddFile('file', 'D:\exportPDF\1CG-2020-08-26-0001.pdf', GetMIMETypeFromFile('D:\exportPDF\1CG-2020-08-26-0001.pdf'));
    try
        
        response := FHttp.Post('http://127.0.0.1:18080/PSSWeb/PDF/uploadPDF.do', MutPartForm);
        WinExec(pChar('chrome.exe --new-window http://127.0.0.1:18080/PSSWeb/supplier/bill/showPDF.pdf?fileName='+response),SW_SHOWNORMAL);
        ShellExecute(Handle,'open','chrome.exe',PChar('--new-window http://127.0.0.1:18080/PSSWeb/supplier/bill/showPDF.pdf?fileName='+response),'',SW_SHOWNORMAL);
       // Messagebox(0, PAnsiChar(response), 'ca', MB_OK);
    finally
        MutPartForm.Free;
        FHttp.Free;
    end;

java端:

CommonsMultipartResolver multipartResolver=new CommonsMultipartResolver(
                request.getSession().getServletContext());
		String meargeFile = "";
		if(multipartResolver.isMultipart(request))
        {
            //将request变成多部分request
            MultipartHttpServletRequest multiRequest=(MultipartHttpServletRequest)request;
            MultiValueMap<String,MultipartFile> fileMap =  multiRequest.getMultiFileMap();
            List<MultipartFile> files=fileMap.get("file");
            String reportFile = ""; 
            for (MultipartFile f : files) {
            	
            	reportFile = ps.InputStreamToFile(f.getInputStream());
            	
            }
           
            
        }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Delphi中使用IdHTTP组件下载大文件可以按照以下步骤进行操作: 1. 创建一个新的Delphi项目,将IdHTTP组件拖放到主窗体上。 2. 在主窗体的事件处理程序中,编写下载功能的代码。 首先,需要设置IdHTTP组件的一些属性,例如超时时间、编码等。接着,根据下载文件的URL地址,调用IdHTTP组件的Get方法进行文件下载。 示例代码如下: ```delphi uses IdHTTP, IdSSL; procedure TForm1.Button1Click(Sender: TObject); var IdHTTP: TIdHTTP; IdSSL: TIdSSLIOHandlerSocketOpenSSL; begin IdHTTP := TIdHTTP.Create(nil); IdSSL := TIdSSLIOHandlerSocketOpenSSL.Create(nil); try IdHTTP.IOHandler := IdSSL; IdHTTP.HandleRedirects := True; IdHTTP.Request.Connection := 'Keep-Alive'; IdHTTP.Request.UserAgent := 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.82 Safari/537.36'; IdHTTP.Request.Accept := 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9'; IdHTTP.Request.AcceptEncoding := 'gzip, deflate, br'; IdHTTP.Request.AcceptLanguage := 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7'; IdHTTP.Get('http://example.com/bigfile.zip', 'C:\Downloads\bigfile.zip'); finally IdSSL.Free; IdHTTP.Free; end; end; ``` 以上代码中,根据实际情况设置了一些请求头信息,如User-Agent、Accept-Encoding等。然后通过Get方法将远程文件下载到本地,下载的文件路径为`C:\Downloads\bigfile.zip`。 需要注意的是,下载大文件时可能需要考虑到网络问题以及服务器的限制。可以添加一些异常处理机制,例如使用try-except语句来处理网络连接异常或文件保存异常。此外,也可以根据下载进度来更新UI界面。 以上就是在Delphi中使用IdHTTP组件下载大文件的简单示例。根据需要可以进行适当的修改和扩展。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值