1

我正在尝试将我的 PhoneGap 应用程序中的图像上传到服务器上的某个文件夹。我的服务器端有宁静的 WS,方法如下:

[OperationContract]
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json,  UriTemplate = "fileUpload")]
    string fileUpload(Stream fileStream); 


public string fileUpload(Stream fileStream)
         {
         try
             {
             FileStream fileToupload = new FileStream("D:\\FileUpload\\" + "images.jpg", FileMode.Create);

             byte[] bytearray = new byte[10000];
             int bytesRead, totalBytesRead = 0;
             do
                 {
                 bytesRead = fileStream.Read(bytearray, 0, bytearray.Length);
                 totalBytesRead += bytesRead;
                 } while (bytesRead > 0);

             fileToupload.Write(bytearray, 0, bytearray.Length);
             fileToupload.Close();
             fileToupload.Dispose();

             return "Success;

             }
         catch (Exception e)
             {
             return e.Message;
             throw (e);
             }                   
         }

我使用了http://docs.phonegap.com/en/2.3.0/cordova_file_file.md.html#FileUploadOptions中最常见的示例 ,它在正确的位置上传图像并给我成功调用,但我无法打开图像在它之后,“Windows 查看器”会显示“损坏、损坏或太大”。当我在记事本++中打开图像时,我在乞求图像上有以下文字:

--*****
Content-Disposition: form-data; name="value1";

test
--*****
Content-Disposition: form-data; name="value2";

param
--*****
Content-Disposition: form-data; name="file"; filename="32"
Content-Type: image/jpeg

当我删除这些部分时,我得到了原始正确的图像。如何在我的服务器端处理这些数据。我想提取图像名称和参数并将其用作字符串,并且在没有这些参数的情况下仅将图像内容推送到我的图像?

谢谢,米洛斯

4

0 回答 0