internal void WcfExecute(Stream istream, string contentType) { string savedFileName, ext, fName; ext = context.ExtensionForContentType(contentType); savedFileName = FileUtil.getTempFileName(Preferences.getTMP_MEDIA_PATH(), "BLOB", string.IsNullOrEmpty(ext) ? "tmp" : ext); GxFile file = new GxFile(Preferences.getTMP_MEDIA_PATH(), savedFileName); file.Create(istream); JObject obj = new JObject(); fName = file.GetURI(); string fileGuid = GxUploadHelper.GetUploadFileGuid(); string fileToken = GxUploadHelper.GetUploadFileId(fileGuid); obj.Put("object_id", fileToken); localHttpContext.Response.AddHeader("GeneXus-Object-Id", fileGuid); localHttpContext.Response.ContentType = MediaTypesNames.ApplicationJson; HttpHelper.SetResponseStatus(localHttpContext, ((int)HttpStatusCode.Created).ToString(), string.Empty); localHttpContext.Response.Write(obj.ToString()); GxUploadHelper.CacheUploadFile(fileGuid, savedFileName, fName, ext, file, localHttpContext); }
public override void webExecute() { try { string savedFileName, ext, fName; if (context.isMultipartRequest()) { localHttpContext.Response.ContentType = MediaTypesNames.TextPlain; var r = new List <UploadFile>(); var fileCount = localHttpContext.Request.GetFileCount(); for (var i = 0; i < fileCount; i++) { string fileGuid = GxUploadHelper.GetUploadFileGuid(); string fileToken = GxUploadHelper.GetUploadFileId(fileGuid); var hpf = localHttpContext.Request.GetFile(i); fName = string.Empty; string[] files = hpf.FileName.Split(new char[] { '\\' }); if (files.Length > 0) { fName = files[files.Length - 1]; } else { fName = hpf.FileName; } ext = FileUtil.GetFileType(fName); savedFileName = FileUtil.getTempFileName(Preferences.getTMP_MEDIA_PATH(), FileUtil.GetFileName(fName), string.IsNullOrEmpty(ext) ? "tmp" : ext); GxFile gxFile = new GxFile(Preferences.getTMP_MEDIA_PATH(), savedFileName); gxFile.Create(hpf.InputStream); string uri = gxFile.GetURI(); string url = (PathUtil.IsAbsoluteUrl(uri)) ? uri : context.PathToUrl(uri); r.Add(new UploadFile() { name = fName, size = gxFile.GetLength(), url = url, type = context.GetContentType(ext), extension = ext, thumbnailUrl = url, path = fileToken }); GxUploadHelper.CacheUploadFile(fileGuid, savedFileName, fName, ext, gxFile, localHttpContext); } UploadFilesResult result = new UploadFilesResult() { files = r }; var jsonObj = JSONHelper.Serialize(result); localHttpContext.Response.Write(jsonObj); } else { Stream istream = localHttpContext.Request.GetInputStream(); string contentType = localHttpContext.Request.ContentType; WcfExecute(istream, contentType); } } catch (Exception e) { SendResponseStatus(500, e.Message); HttpHelper.SetResponseStatusAndJsonError(localHttpContext, HttpStatusCode.InternalServerError.ToString(), e.Message); } finally { try { context.CloseConnections(); } catch { } } }