1
한 번에 하나의 '저장'버튼을 사용하여 텍스트 또는 이미지를 업로드하는 시나리오가 있습니다. 그래서, 텍스트를 저장하려고 할 때, 그것은 잘 작동, 응답을주는 & 게시하지만 이미지를 저장하려고 할 때 그것은 잘 게시되지만 응답을받지 않습니다. 빈 결과/응답을 받고 있습니다.
내 코드가 나는 또한 네트워크 이미지를 부착하고[Authorize]
[HttpPost]
public ActionResult AddQuib(string body, int time, bool isSeedQuib, string SeedQuibType, int parentId = 0, string movieId = "", bool IsScreenshot = false)
{
QuibStream quib = new QuibStream();
QuibStream objQuib = new QuibStream();
try
{
//quib.MovieId = Convert.ToInt32(Session["MovieId"]);
if (movieId.Length > 0)
quib.MovieId = Convert.ToInt32(movieId);
else
quib.MovieId = (Request.Params["MovieId"] != null && Convert.ToString(Request.Params["MovieId"]).Trim().Length > 0) ? Convert.ToInt32(Convert.ToString(Request.Params["MovieId"]).Trim()) : 0;
quib.UserId = Convert.ToInt32(cookie["UserId"]);
// this replaces new line also with single space
//quib.Body = Regex.Replace(body.Trim(), @"\s+", " ");
if (!IsScreenshot)
quib.Body = body.Trim();
else
quib.Body = body;
RegexOptions options = RegexOptions.None;
Regex regex = new Regex(@"[ ]{2,}", options);
if (!IsScreenshot)
quib.Body = regex.Replace(quib.Body, @" ");
quib.Time = time;
quib.IsQuibZero = time == 0 ? true : false;
quib.ParentId = parentId == 0 ? 0 : parentId;
quib.IsSeedQuib = isSeedQuib;
quib.SeedQuibType = quib.IsSeedQuib ? SeedQuibType : null;
quib.IsScreenshot = IsScreenshot;
if (IsScreenshot)
{
var fileType = quib.Body.Split('/')[1];
fileType = fileType.Split(';')[0];
Guid fileNameGuid = Guid.NewGuid();
string ImageString = quib.Body.Split(',')[1];
var newImageByte = Convert.FromBase64String(ImageString);
byte[] DocBytesArray = new byte[newImageByte.Length + 1];
if (ImageString != null)
DocBytesArray = newImageByte;
//byte[] bytes = DocBytesArray;
var fs = new BinaryWriter(new FileStream(System.Web.HttpContext.Current.Server.MapPath("~\\Images\\Screenshots") + "\\" + fileNameGuid.ToString() + "." + fileType, FileMode.Append, FileAccess.Write));
fs.Write(DocBytesArray);
fs.Close();
quib.Body = @"/Images/Screenshots/" + fileNameGuid.ToString() + "." + fileType;
}
objQuib = _quibService.AddQuib(quib);
}
catch (Exception ex)
{
WinEventLog.eventLog.WriteEntry(string.Format("QuibStream 'AddQuib()' Failed. Error : '{0}'", ex.Message), EventLogEntryType.Error, 100);
return Json(null);
}
var jsonResult = Json(objQuib, JsonRequestBehavior.AllowGet);
jsonResult.MaxJsonLength = int.MaxValue;
return jsonResult;
}
$.ajax({
async: false,
url: localStorage.getItem('environment') + 'QuibStream/AddQuib',
type: 'POST',
dataType: 'text',
data: { body: body, time: seconds, isSeedQuib: IsSeedQuib, seedQuibType: SeedQuibType, parentId: SelectedQuibId, movieId: queryStringValuefromKey("movieId"), IsScreenshot: IsScreenshot },
success: function (response) {
if (response != undefined && response != null && response.length > 0) {
var SeedquibClass = "";
quibContent = JSON.parse(response);
}
}
});
아래처럼 ... 제발 도와주세요. 누군가가 실제 문제가 어디에 있는지 말해 줄 수 있다면. 모든 사람에게
콘솔에 오류가 있습니까? 또한,'async : false'를 제거하십시오. 그것은 끔찍한 –
당신이 데이터 형식을 사용하는 야기 : "텍스트 :"!! 어떻게 데이터 유형을 가진 이미지를 보낼 것으로 기대하십니까? – AthMav
@AthMav'dataType'은 당신이 보내는 것이 아니라 당신이 얻는 것입니다. 그러나 귀하의 의견은 어떤면에서 정확합니다. 이것은 분명히 –