Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 254081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:49:00+00:00 2026-05-11T21:49:00+00:00

Here’s my method [AcceptVerbs(HttpVerbs.Post)] public void SaveImage(FormCollection formValues) { byte[] contents = Convert.FromBase64String(Request.Form[file]); System.IO.File.WriteAllBytes(Server.MapPath(Request.Form[name]),

  • 0

Here’s my method

    [AcceptVerbs(HttpVerbs.Post)]
    public void SaveImage(FormCollection formValues)
    {
        byte[] contents = Convert.FromBase64String(Request.Form["file"]);
        System.IO.File.WriteAllBytes(Server.MapPath(Request.Form["name"]), contents);
    }

It is getting posted to from this actionscript method:

    public function encodeAndSave(e:MouseEvent = null):void
    {
        var date:Date = new Date();
        var by:ByteArray = PNGEnc.encode(canvas.main_bdata);
        var req:URLRequest = new URLRequest(server_path+"Home/SaveImage");
        var params:URLVariables = new URLVariables();
        params.file = Base64.encodeByteArray(by);
        params.name = "MyImage.png";
        req.method = URLRequestMethod.POST;
        req.data = params;
        var ldr:URLLoader = new URLLoader(req);

        ldr.addEventListener(Event.COMPLETE, complete);

        ldr.load(req);

        function complete(e:Event):void
        {
            navigateToURL(new URLRequest("?" + Math.random()), "_self");

        }

    }

But when the encodeAndSave method runs, no file gets saved to the server…

Does anyone know how to tell if the SaveImage method has even ran? Also, when I type:
http://www.mysite.com/Home/SaveImage into the address bar it says “The resource cannot be found”.

Anyone have any ideas as to why it would be doing this or what i can do to try to figure it out?

If you need any more information please let me know and I’ll update my question.

Thanks,
Matt

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T21:49:00+00:00Added an answer on May 11, 2026 at 9:49 pm

    I had a [lot] of trouble with this and I used this in the end;

    View:

    <% using (Html.BeginForm( "PhotoAdd", "Photos", FormMethod.Post, new { enctype = "multipart/form-data" }))   { %>
    
    <input type="file" id="file" name="file" class="field" style="width:300px;"/>
    
    <%} %>
    

    Controller:

    var file = Request.Files["file"];
    byte[] buf = new byte[file.ContentLength];
    file.InputStream.Read(buf, 0, file.ContentLength);
    

    I’m not sure whether this is what you are looking for but like I said I have a lot of problems allowing my users to upload a photo of themselves in my web site.

    Basically I have a View which contains a field of type “file” on it and a “Submit” button for the post back event.

    Then in the controller I have the following;

        [AcceptVerbs( HttpVerbs.Post ), Authorize]
        public ActionResult PhotoAdd(FormCollection collection)
        {
            try
            {
                var file = Request.Files["file"];
    
                byte[] buf = new byte[file.ContentLength];
                file.InputStream.Read(buf, 0, file.ContentLength);
    

    The difficulty I ran into was getting the controller to get the request along with the file name and path. Once I had that I could convert the file to an array of bytes that I could then save to a SQL Database and an Image field.

    The one biggest thing I was missing was the Form method in the View which needs to read

    <% using (Html.BeginForm( "PhotoAdd", "Photos", FormMethod.Post, new { enctype = "multipart/form-data" }))   { %>
    

    The enctype allows you to pick up the filename and path of the selected file and for the controller to be able to grab the inputstream. Without it I found that either Request.Files was empty or that it only contained the file name and hence could not open it.

    Once you have saved the image to your database, displaying it is a doddle.

    I hope this answers your question.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 220k
  • Answers 220k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The Cookie approach should work. The other thing you can… May 12, 2026 at 11:55 pm
  • Editorial Team
    Editorial Team added an answer You could break it down into multiple strings for the… May 12, 2026 at 11:55 pm
  • Editorial Team
    Editorial Team added an answer Looking into sed documentation some more and following advice from… May 12, 2026 at 11:55 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
Here's a basic regex technique that I've never managed to remember. Let's say I'm
Here's a problem I ran into recently. I have attributes strings of the form

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.