开发者

ASP.net MVC file upload to Amazon S3 with progress

Good day,

I have a ASP.net MVC app that needs to upload files to Amazon S3 with progress. I found a neat control called Flajaxian that does the job pretty well. The issue is that now I want to insert a row of data into a DB that keeps track of the uploads. If you look at the code below the control has a FileUploader1_ConfirmUpload event that fires after the upload has completed. Url.Action("Upload", "TracksController") does not do what I want it to, which is fire the Upload Action in the TrackController Controller. This is the first time I've worked with MVC so I'm hoping there is a simple solution.

I originally had a submit button to perform the upload in code like this <div class="submitBtnDiv"><input type="submit" value="Submit" class="submitBtn" id="trackAdd" /></div>. but now the upload is asynchronous so i want to do the same postback

Thank you to everyone that takes the time to read through this, and even more to those that try to solve it.

 <div class="contentsAcc"><form id="form2" runat="server" style="width:400px">
                <script runat="server">
                    private void FileUploader1_FileNameDetermining(object sender, FileNameDeterminingEventArgs e)
                    {
                        e.FileName = SessionWrapper.PersonId.ToString() + "_" + e.FileName;
                    }
                </script>
                <script runat="server">
                    private void FileUploader1_ConfirmUpload(object sender, ConfirmUploadEventArgs e)
                    {
                        Url.Action("Upload", "TracksController");                            
                    }
                </script>
                    <fjx:FileUploader ID="FileUploader1" runat="server">
                        <Adapters>
                            <fjx:DirectAmazonUploader   OnFileNameDetermining="FileUploader1_FileNameDetermining" OnConfirmUpload="FileUploader1_ConfirmUpload"
                                AccessKey="WebConfig:AmazonAccessKey" 
                                SecretKey="WebConfig:AmazonSecretKey"
                                BucketName="tracksupload" />
                        </Adapters>
                    </fjx:FileUploader>

        </form></div>

Ok, so I've tried to change my approach a bit from the above yesterday. Instead of trying to fire the Action of the TracksController i want to move that Action code into the Confirm_Upload event. But now I still need to get the values of the textboxes. Because MVC doesnt remember state it is proving difficult. Here are the textBoxes. they are on the same page as the code above.

 <label for="BandName">Artist</label> 
       <%=Html.TextBox("Artists") %><%:Html.ValidationMessage("Artist","*")%>
        <div class="clearfix">
        </div>
        <label for="SongName">Song Title
        </label>
          <%=Html.TextBox("SongName开发者_如何学Go") %><%:Html.ValidationMessage("SongName","*")%>
        <div class="clearfix">
        </div>

Is it possible to pull the values of the textbox and have it sent to the Confirm_Upload event which happens server side? If not with server code then maybe JavaScript client side?

The upload control im using is the only one that does excatly what I want, but it is web forms, the site is MVC. So I have a web forms control on a mvc page. I want to use MVC textbox values and pass it to the web forms control for processing.


Url.Action simply returns a URI. Are you trying to redirect?

Sometimes WebForms events work in MVC so I was seeing if it was as simple as you needing to redirect.


Your main problem is you are trying to use WebForms code in what looks like a MVC page. This is mostly incompatible and you'll need to wireup javascript yourself or use another of the many javascript file upload controls directly in your view.

I can't recommend anything because I'm not familiar with S3 uploading. Maybe another SO user can answer better.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜