Witam,
mam taki problem, próbuję wysłać plik 100MB do mojego Web Service. ale po wysłaniu formularza nić się nie dzieje.
Małe pliki się wysyłają. W jaki sposób mogę wysłać duży plik.
Kod dla Web Serwisu
[WebService( Namespace = "http://tempuri.org/" )]
[WebServiceBinding( ConformsTo = WsiProfiles.BasicProfile1_1 )]
[System.ComponentModel.ToolboxItem( false )]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class MyService : WebService
{
public AuthUser User;
static string addressIP = ConfigurationManager.ConnectionStrings["addressIP"].ConnectionString;
[WebMethod]
public string HelloWorld()
{
return "Hello ";
}
[WebMethod]
public string UploadFile( byte[] file, string fileName )
{
DateTime dt = DateTime.Now;
string sDate = dt.ToString( "yyyy-MM-dd" );
string sPath = "";
string sExt = fileName.Substring( fileName.Length - 3 );
double dLatitdue = 0;
double dLongitude = 0;
string sLatitdue = "0.000000";
string sLongitude = "0.000000";
string dateTaken = "";
bool bIsImage = false;
System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex( ":" );
if (sExt.Equals( "png" ) || sExt.Equals( "jpg" ) || sExt.Equals( "bmp" ))
{
sPath = ConfigurationManager.AppSettings["pathImg"] + "\\" + sDate;
bIsImage = true;
}
else
if (sExt.Equals( "avi" ) || sExt.Equals( "mp4" ) || sExt.Equals( "mov" ))
{
sPath = ConfigurationManager.AppSettings["pathVideo"] + "\\" + sDate;
bIsImage = false;
}
bool exists = System.IO.Directory.Exists( sPath );
if (!exists)
System.IO.Directory.CreateDirectory( sPath );
try
{
MemoryStream ms = new MemoryStream( file );
FileStream fs = new FileStream( sPath + "\\" + fileName, FileMode.Create );
ms.WriteTo( fs );
// clean up
ms.Close();
fs.Close();
fs.Dispose();
if (bIsImage)
{
Image img = new Bitmap( sPath + "\\" + fileName );
foreach (PropertyItem propItem in img.PropertyItems)
{
switch (propItem.Type)
{
case 5:
if (propItem.Id == 2) // Latitude Array
dLatitdue = Math.Round( GetLatitudeAndLongitude( propItem ), 6 );
if (propItem.Id == 4) //Longitude Array
dLongitude = Math.Round( GetLatitudeAndLongitude( propItem ), 6 );
break;
}
if (propItem.Id == 36867)
dateTaken = r.Replace( Encoding.UTF8.GetString( propItem.Value ), "-", 2 );
}
if (dLatitdue != 0.0)
sLatitdue = dLatitdue.ToString();
if (dLongitude != 0.0)
sLongitude = dLongitude.ToString();
}
System.Diagnostics.Debug.Write( sLatitdue + ", " + sLongitude );
return "powiodło się";
}
catch (Exception ex)
{
// return the error message if the operation fails
return ex.Message.ToString();
}
}
private static double GetLatitudeAndLongitude( PropertyItem propItem )
{
try
{
uint degreesNumerator = BitConverter.ToUInt32( propItem.Value, 0 );
uint degreesDenominator = BitConverter.ToUInt32( propItem.Value, 4 );
uint minutesNumerator = BitConverter.ToUInt32( propItem.Value, 8 );
uint minutesDenominator = BitConverter.ToUInt32( propItem.Value, 12 );
uint secondsNumerator = BitConverter.ToUInt32( propItem.Value, 16 );
uint secondsDenominator = BitConverter.ToUInt32( propItem.Value, 20 );
return (Convert.ToDouble( degreesNumerator ) / Convert.ToDouble( degreesDenominator )) + (Convert.ToDouble( Convert.ToDouble( minutesNumerator ) / Convert.ToDouble( minutesDenominator ) ) / 60) +
(Convert.ToDouble( (Convert.ToDouble( secondsNumerator ) / Convert.ToDouble( secondsDenominator )) / 3600 ));
}
catch (Exception)
{
return 0;
}
}
po stronie klienta
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title of the document</title>
<script src="Scripts/jquery-1.10.2.js"></script>
</head>
<body>
<form name="fileForm" method="post">
<input type="hidden" id="filedata" />
<input type="file" id="file-select" name="file"/>
<button type="submit" id="upload-button" onclick="runCode()">Upload</button>
</form>
<script>
function runCode() {
var file = document.getElementById('file-select').files[0];
if (file) {
UploadMe(file);
}
}
function UploadMe(readFile) {
var reader = new FileReader();
reader.onload = loaded;
reader.readAsArrayBuffer(readFile); //array buffer
}
function loaded(evt) {
var fileString = evt.target.result;
var X = _arrayBufferToBase64(fileString); // this is the method to convert Buffer array to Binary
var file = $("#file-select").val();
var files = file.split('\\');
var soapEnv =
"<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'> \
<soap:Body>\
<UploadFile xmlns='http://tempuri.org/'>\
<file>" + X + "</file>\
<fileName>" + files[files.length - 1] + "</fileName>\
</UploadFile>\
</soap:Body>\
</soap:Envelope>";
$.ajax({
url: "http://localhost:8083/Authentication.asmx",
beforeSend: function (xhr) { xhr.setRequestHeader("SOAPAction", "http://tempuri.org/UploadFile"); },
type: "POST",
dataType: "xml",
data: soapEnv,
complete: processResult,
contentType: "text/xml; charset=\"utf-8\""
});
}
function processResult(xData, status) {
alert("Uploaded SuccessFully");
}
function _arrayBufferToBase64(buffer) {
var binary = '';
var bytes = new Uint8Array(buffer);
var len = bytes.byteLength;
for (var i = 0; i < len; i++) {
binary += String.fromCharCode(bytes[i]);
}
return window.btoa(binary);
}
</script>
</body>
</html>
Z góry dziękuje za pomoc
Pozdrawiam
PiK