0

I'm implementing stripe in my action ChargeFileUpload, on it should return to another action and upload said file.

Note these are not real class names, its just for the purpose of explanation.


public async Task<IActionResult> ChargeFileUpload(ProfileViewModel model)
{
            user = await userManager.GetUserAsync(User);
            string successUrl = $"{Request.Scheme}://{Request.Host.Value}" + Url.Action("UploadFile", "Member", new { model.Obj });
            Session session;

            ... extra code..

}

Heres the thing, the ProfileViewModel contains an class which contains a file lets call the class it ClassWhichContainsFile and the object for that class obj.

On success of the payment, it goes to this method:

public async Task<IActionResult> UploadFile(ClassWhichContainsFile obj)
{
        ApplicationUser user = await userManager.GetUserAsync(User);

        if (user != null)
        {
            //add file to users account
        }

        return RedirectToAction("Profile", new { userName = user.UserName });
}

The issue I'm facing is that whenever I pass the obj to the UploadFile method, all the properties that I want are there, but the IFormFile is not. When I am in the ChargeFileUpload method the IFormFile is there.

How can I get my IFormFile to be passed to the UploadFile method correctly?

Derrick Rose
  • 664
  • 2
  • 9
  • 21
  • 3
    I'd suggest saving the file somewhere with an ID, and then pass the ID. – ProgrammingLlama Mar 27 '20 at 03:11
  • 3
    You really can't convince browser to re-send file second time in unrelated POST request. As @John suggested saving file on first request server side is really only sensible option. You can push file content to new page and construct POST request clients side (like https://stackoverflow.com/questions/2198470/javascript-uploading-a-file-without-a-file/2198524#2198524) but that may take long time as you need to send same file 3 time between browser and server. – Alexei Levenkov Mar 27 '20 at 05:19

0 Answers0