none
win8应用商店程序,怎么上传图片到服务器? RRS feed

全部回复

  • 你好 heller,

    我建议如果是上传图片的话,还是使用HttpClient类,BackgroundUploader是用于大文件的,请参考文档BackgroundUploader 类

    注意  后台传输主要为资源(如,视频、音乐和大图像)的长时间传输操作而设计。对于涉及较小资源的转换(即,几个 KB)的短期操作,请使用 Windows.Web.Http 命名空间。

    所以有可能BackgroundUploader返回的Status值不是很准确。

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    2014年6月19日 5:51
    版主
  • 你好 heller,

    我建议如果是上传图片的话,还是使用HttpClient类,BackgroundUploader是用于大文件的,请参考文档BackgroundUploader 类

    注意  后台传输主要为资源(如,视频、音乐和大图像)的长时间传输操作而设计。对于涉及较小资源的转换(即,几个 KB)的短期操作,请使用 Windows.Web.Http 命名空间。

    所以有可能BackgroundUploader返回的Status值不是很准确。

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    怎么还是不行啊,能给个例子吗?
    2014年6月24日 2:21
  • 参考下这个:http://code.msdn.microsoft.com/windowsapps/HttpClient-sample-55700664,试试看行不行

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    2014年6月24日 6:52
    版主
  •  Platform::String^ uriString = L"http://192.168.1.15:8088/Server/upload_access.php";
    	  Uri^ uri = ref new Windows::Foundation::Uri(uriString);
    
    	  create_task(m_SaveFolder->GetFileAsync(Save_PhotoName)).then([this, uri](StorageFile^ file) 
    	  {
    		  create_task(file->OpenAsync(FileAccessMode::Read)).then([this, uri](IRandomAccessStream^ stream) 
    		  {
    			  HttpStreamContent^ streamContent = ref new HttpStreamContent(stream);
    			  HttpRequestMessage^ request = ref new HttpRequestMessage(HttpMethod::Post, uri);
    			  request->Content = streamContent;
    			  HttpClient^ httpClient = ref new HttpClient();
    			  return create_task(httpClient->SendRequestAsync(request));
    		  });
    	  }).then([this](task<void> previousTask)
    	  {
    		  try {
    			  previousTask.get();
    		  }
    		  catch (Exception^ ex)
    		  {
    			  // LogException("Upload Error", ex);
    		  }
    		  catch (task_canceled&)
    		  {
    			  // Do nothing - we canceled the task.
    		  }
    	  }, task_continuation_context::use_current());


    关键代码就是这样,怎么还是不行呢,有什么问题吗,服务器是Apache服务器,使用http协议,设置了“file”标头,怎么样才行啊?

    • 已编辑 heller灬 2014年6月27日 7:12 编辑有误
    2014年6月27日 7:07
  • 你好,问题解决了么?

    照理说跟Web服务器没有什么关系,不过Apache的地址算是Localhost么,本地是不可以的哦~

    所以你的代码运行是正常的,但是图片上传不上去对吧?你能提供我一个Demo让我做一下测试么?我需要一整个项目,很有可能是你项目中其他地方影响了上传。

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    2014年7月8日 8:10
    版主