0
저는 응용 프로그램에서 작업 중이며 이미지를 업로드하고 있습니다. 문제는 WCF 코드가 제대로 저장되지 않아 이미지가 나옵니다. 이미지를 유효하지 않은 것으로 저장하십시오.WCF 서비스가 Ionic App에서 이미지를 저장하지 않습니다.
[OperationContract]
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "upload2/{fileName}")]
string Upload2(string fileName, Stream fileStream);
public string Upload2(string fileName, Stream fileStream)
{
try
{
FileStream fileToupload = new FileStream(WebConfigurationManager.AppSettings["FilePath"] + fileName, 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 "succ";
}
catch (Exception ex)
{
return ex.Message + " - " + ex.InnerException;
}
}
코드 컨트롤러 AngularJS와,
$scope.subirFoto = function() {
var options = new FileUploadOptions();
options.fileKey = "post";
options.fileName = imageURI.substr(imageURI.lastIndexOf('/')+1);
options.mimeType = "image/jpeg";
options.chunkedMode = false;
var ft = new FileTransfer();
ft.upload(imageURI, encodeURI("http://192.68.1.182:8085/IServiceTopStore.svc/upload2/"+options.fileName), win, fail, options);
}