Skip to content

Commit

Permalink
Cherry pick branch 'genexuslabs:rest-service-as-controller' into beta
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiamurialdo authored and Beta Bot committed Dec 7, 2024
1 parent 4fc8cf7 commit 87ef0c3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
16 changes: 12 additions & 4 deletions dotnet/src/dotnetcore/GxClasses.Web/Middleware/GXRestServices.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
Expand Down Expand Up @@ -98,12 +99,19 @@ protected bool RestParameter(string parameterName, string parameterValue)
return false;
}
}
/*public void UploadImpl(Stream stream)
protected ActionResult UploadImpl()
{
GXObjectUploadServices gxobject = new GXObjectUploadServices(context);
IncomingWebRequestContext request = WebOperationContext.Current.IncomingRequest;
gxobject.WcfExecute(stream, request.ContentType, request.ContentLength, request.Headers[HttpHeader.XGXFILENAME]);
}*/
string fileGuid;
string fileToken;
using (Stream stream = Request.Body)
{
fileToken = gxobject.ReadFileFromStream(stream, Request.ContentType, Request.ContentLength.GetValueOrDefault(), Request.Headers[HttpHeader.XGXFILENAME], out fileGuid);
}
Response.Headers.Append(HttpHeader.GX_OBJECT_ID, fileGuid);
SetStatusCode(HttpStatusCode.Created);
return GetResponse(new {object_id = fileToken});
}
protected void ErrorCheck(IGxSilentTrn trn)
{
if (trn.Errors() == 1)
Expand Down
1 change: 1 addition & 0 deletions dotnet/src/dotnetframework/GxClasses/Helpers/HttpHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class HttpHeader
public static string LAST_MODIFIED = "Last-Modified";
public static string EXPIRES = "Expires";
public static string XGXFILENAME = "x-gx-filename";
public static string GX_OBJECT_ID = "GeneXus-Object-Id";
internal static string ACCEPT = "Accept";
internal static string TRANSFER_ENCODING = "Transfer-Encoding";
internal static string X_CSRF_TOKEN_HEADER = "X-XSRF-TOKEN";
Expand Down
30 changes: 19 additions & 11 deletions dotnet/src/dotnetframework/GxClasses/Middleware/GXHttpServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,20 @@ public override void webExecute()

internal void WcfExecute(Stream istream, string contentType, long streamLength, string gxFileName)
{
string ext=null, fName=null;

string fileToken = ReadFileFromStream(istream, contentType, streamLength, gxFileName, out string fileGuid);
JObject obj = new JObject();
obj.Put("object_id", fileToken);

localHttpContext.Response.AddHeader(HttpHeader.GX_OBJECT_ID, fileGuid);
localHttpContext.Response.ContentType = MediaTypesNames.ApplicationJson;
HttpHelper.SetResponseStatus(localHttpContext, HttpStatusCode.Created, string.Empty);
localHttpContext.Response.Write(obj.ToString());
}

internal string ReadFileFromStream(Stream istream, string contentType, long streamLength, string gxFileName, out string fileGuid)
{
string ext = null, fName = null;
if (!string.IsNullOrEmpty(gxFileName))
{
ext = Path.GetExtension(gxFileName);
Expand All @@ -373,23 +386,18 @@ internal void WcfExecute(Stream istream, string contentType, long streamLength,
{
fName = string.Empty;
}
string tempDir = Preferences.getTMP_MEDIA_PATH();
GxFile file = new GxFile(tempDir, FileUtil.getTempFileName(tempDir, fName), GxFileType.PrivateAttribute);
string tempDir = Preferences.getTMP_MEDIA_PATH();
GxFile file = new GxFile(tempDir, FileUtil.getTempFileName(tempDir, fName), GxFileType.PrivateAttribute);
file.Create(new NetworkInputStream(istream, streamLength));

JObject obj = new JObject();
fName = file.GetURI();
string fileGuid = GxUploadHelper.GetUploadFileGuid();
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, HttpStatusCode.Created, string.Empty);
localHttpContext.Response.Write(obj.ToString());

GxUploadHelper.CacheUploadFile(fileGuid, $"{Path.GetFileNameWithoutExtension(fName)}.{ext}", ext, file, context);
return fileToken;
}

protected override bool IntegratedSecurityEnabled
{
get
Expand Down

0 comments on commit 87ef0c3

Please sign in to comment.