德尔福 - 如何使用拖动和上传图片上传下降?

时间:2016-08-27 09:20:54

标签: delphi delphi-xe2

我尝试构建一个应用程序,将一些数据上传到网站。一切都还可以,但在最后一次填充是上传到input type=file的图片。我尝试了很多来自世界各地的代码,但是我失败了,因为我不理解HTTP而且它像这段代码一样复杂:

procedure PostToURL(URL: OleVariant; EncodedStr, FileName: String);
var
  i: Integer;
  Post, Header: OleVariant;
  rez: String;
  FileStream: TFileStream;
begin
  // preberemo binarno datoteko
  FileStream:=TFileStream.Create(FileName,fmOpenRead or fmShareDenyNone);
  Try
   SetLength(Rez, FileStream.Size);
         FileStream.ReadBuffer(Pointer(Rez)^, FileStream.Size);
   Finally
    FileStream.Free;
  end;

  // The post must be an array. But without null terminator (-1)
  Post := VarArrayCreate([0, Length(EncodedStr) - 1], varByte);

  // Put Post in array
  for I := 1 to Length(EncodedStr) do
    Post[I - 1] := Ord(EncodedStr[I]);

  Header := 'Content-Type: multipart/form-data; boundary=----------ZcpvRS7HNeFzxVsIlOwdUo'+#13#10+#13#10+#13#10;
  // enako z ali brez tega
  //Header := Header+'------------ZcpvRS7HNeFzxVsIlOwdUo' + #13#10;
  //Header := Header+'Content-Disposition: form-data; name="MAX_FILE_SIZE"' + #13#10 + #13#10;
  //Header := Header+'3072000'+#13#10;
  Header := Header+'----------ZcpvRS7HNeFzxVsIlOwdUo' + #13#10;
  Header := Header+'content-disposition: form-data; name="ThisFile" filename="'+ExtractFileName(FileName)+'"'+#13#10;
  Header := Header+'Content-Transfer-Encoding: binary' + #13#10;
  Header := Header+'Content-size: '+IntToStr(1) + #13#10; // GetFileSize(FileName)
  Header := Header+'Content-Type: image/bmp' + #13#10 + #13#10;
  Header := Header+ Rez + #13#10;
  Header := Header+'------------ZcpvRS7HNeFzxVsIlOwdUo' + #13#10;
  Header := Header+'Content-Disposition: form-data; name="Upload"' + #13#10 + #13#10;
  Header := Header+ 'Upload' + #13#10;
  Header := Header+'----------ZcpvRS7HNeFzxVsIlOwdUo--';
  WebMANForm.WebBrowser1.Navigate2(URL, EmptyParam, EmptyParam, Post, Header);
end;

HTML代码为:

                    </td>
<td rowspan="5" class="requestphoto">
<img id="image" runat="server" src="addOmraVisa_files/GetImage.png" height="150px" width="150px">
<div class="t-widget t-upload"><div class="t-dropzone"><div class="t-button t-upload-button"><span>... استعراض</span><input autocomplete="off" id="PersonalPhoto" name="PersonalPhoto" type="file"></div><em>drop files here to upload</em></div></div>
<br>
</td>

在最后的HTML页面中,代码如下:

jQuery(document).ready(function(){
jQuery('#EmbbasyCode').tDropDownList({data:[{"Text":"","Value":""},{"Text":"تونس","Value":"303"}], index:1});
jQuery('#PersonalPhoto').tUpload({multiple:false, showFileList:false, async:{"saveUrl":"/Omra/SaveOmraPersonalPhoto","removeUrl":"/Omra/RemovePersonalPhoto","autoUpload":true}, onSuccess:OnSuccess, onError:OnError, onRemove:OnRemove, localization:{"cancel":"إلغاء","retry":"Retry","select":"... استعراض","remove":"Remove","uploadSelectedFiles":"Upload files","dropFilesHere":"drop files here to upload","statusFailed":"failed","statusUploaded":"uploaded","statusUploading":"uploading"}});
jQuery('#COMING_THROUGH').tDropDownList({data:[{"Text":"جوا","Value":"2"},{"Text":"برا","Value":"1"},{"Text":"بحرا","Value":"3"},{"Text":"مفتوح","Value":"4"}]});});

我想改变拖动和放大我觉得它比HTTP容易。我知道了 Delphi: Simulating a drag and drop from the clipboard to EmbeddedWB’s IHTMLElement 但是我希望在运行时隐藏浏览器而不会让用户看到任何东西, 谁能帮我?我怎样才能解决这个大问题... 假设我有编辑器和浏览器(twebbrowser或TEmbeddedWB) edit.text =单击按钮图片上传时的完整图片路径和按钮 从编辑中的路径到dropzone ... 感谢。

0 个答案:

没有答案