Jump to content

Downloads - REST API - Version date is not set

Go to solution Solved by Marc Stridgen,

Recommended Posts


I'm using the REST API to upload files

I use the following endpoints: "index.php?/downloads/files" and "index.php?/downloads/files/{fileId}/history" (depending if I'm uploading a new version for an existent file or not)

Anyway, regardless of the endpoint, all the files that I uploaded through the API are stored with a version date of "Released January 1, 1970"

When I upload them via the website, the version date is stored properly, this only happens when I use the REST API to upload files


Edited by BraCa
Link to comment
Share on other sites

On 11/7/2023 at 2:13 PM, Marc Stridgen said:

Please could you show the code you are using to upload those?

Yes, but it's not PHP, it's written in C#, but here it goes

        var fileContentsAsByteArray = await File.ReadAllBytesAsync(filepath).ConfigureAwait(false);
        var fileContents = HttpUtility.UrlEncode(fileContentsAsByteArray);

        var body = new Dictionary<string, string>
            { "category", request.CategoryId.ToString() },
            { "author", request.AuthorId.ToString() },
            { "title", HttpUtility.UrlEncode(request.Title)},
            { "description", HttpUtility.UrlEncode(request.Description)},
            { $"files[{request.Filename}]", fileContents},

        if (!string.IsNullOrWhiteSpace(request.Version))
            body["version"] = HttpUtility.UrlEncode(request.Version);

        if (!string.IsNullOrWhiteSpace(request.Changelog))
            body["changelog"] = HttpUtility.UrlEncode(request.Changelog);

        var bodyString = body.ConvertToQueryString();
        var uriPath = fileId.HasValue ? $"index.php?/downloads/files/{fileId.Value}/history" : "index.php?/downloads/files";

        var response = await httpClient.PostAsync<UploadFileResult>(
            contentType: "application/x-www-form-urlencoded").ConfigureAwait(false);


Link to comment
Share on other sites

3 hours ago, Jim M said:

If you supply a date or updated value passed appropriately, do you get the same response?

I will try, but just to be clear, do you mean to add to the body new properties named "date" and "updated"? 
Also, in what format should those values be?

Link to comment
Share on other sites

  • 2 months later...
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...