How to upload a file from console application to MVC website? - asp.net-mvc

I have an MVC application that can accept a file. It basically follows the example shown here for uploading a single file: https://www.c-sharpcorner.com/article/upload-files-in-asp-net-mvc-5/.
However, I would like to create a command line console utility from which I can upload a file. I think that I very generally understand this would likely involve creating a web request, adding certain headers, and attaching a byte array for the file but I'm a bit lost as to what this entails specifically.
Also for the console application, I will obviously modify the action to return a json result instead of a view.

Oh my gosh it was so much easier than I expected. I just used the WebClient.UploadFile() method and it worked like a charm.

Related

Embed PDF in a website, allow user to modify editable fields in PDF, and save back to the server

I am writing a Program in Rub On Rails 4.x and I have to take PDF files with defined fields that can be filled out, fill in data from a form submission(This part is DONE!), and lastly allow the user to modify the saved PDF file on the server and overwrite said PDF after making their modifications.
Like I said I have already gotten the PDF files filled out with what has been submitted in the form through pdftk . What I now need to do is provide a server side editing capability to the said PDF files on server generated from the first step of the process.
I have seen similar posts but none wanting to do the same thing I do. If I am wrong links would be great. Thanks in advance for all your help!
After lots of digging and research here is what I have found to be the facts surrounding this issue and implementing a program to allow embedding the PDF file, editing it, and saving it back to the server. This process would be great however from what I can tell there is nothing out there that really does this for Ruby On Rails. To quote #Nick Veys
Seems like you need to find a Javascript PDF editor you can load your PDF into, allow the user to modify it, and ultimately submit it back to the server. Seems like they exist, here's one for ASP projects
You are correct but still wrong in the sense that yes there is one for ASP projects however that is Microsoft Based, yes I know that it can run on Linux environments through Mono. However to the point it would appear in this instance that a Ruby On Rails specific solution is indeed needed.
The solution that we have come up with is as follows
1. Use a PDF editing package in the linux repositories like PDFtk
2. You then render a page with the PDF embeded on one side and a form representing the live fields in the PDF to take input.
3. Once submitted you use PDFtk to write the values into a new template PDF file and overwrite what was previously stored.
This requires a few additional steps to process the data than I really care for myself. However it is the best solution that our team could come up with, without bleeding the project budget dry for just 1 piece of functionality.
I hope this helps anyone else looking to do the same thing in Ruby On Rails.
I have done something like this using my company's .NET product. It can also be done using its Java version too.
http://www.gnostice.com/nl_article.asp?id=255&t=Save_Form_Submit_Data_Back_To_Original_PDF_Document_In_NET

Moving template to separate files

In a Rails app I consume data from an external service in json format.
Right now I do something like.
json-data = $get ....
template = "<div>..{{whatever}}..</div>"
$('#target').append Mustache.to_html(template, json-data)
And it works fine. However, more and more the app and the templates grow I wish to be able to store the template in separate files (also because I'm starting to have some duplications).
I have created the folder app/assets/templates and put there myTemp.mustache template. But, now I don't know how to load it into my script.
Any suggestions?
Thanks and have a nice day.
You should take a look at the awesome gem http://github.com/railsware/smt_rails . It is very easy to use
There is great cast from RyanB Sharing Mustache Templates and here is the sample code episode-295 in case you don't have pro subscription. Also look in this gem.

Is there a clever way to pass a yml locale file to my client for translation?

I have finished a rails project using i18n and now I need to pass all the text in the website to our client so that he can translate them and we can include additional locales to our app.
The problem is our client is not a geek and if we give them the actual YAML file, they will use MS Word to edit it and we'll lose all the proper markup in the process ("\n" for new lines, one line text, etc...).
How would you handle this process?
Is there a better way than giving the client a .doc file and then loosing a day to clean the text afterwards and manually converting it back to YAML?
Thanks in advance,
Augusto
This is exactly what Locale was created for : you upload your YAML files, your client/translator edits the content and you sync YAML back down. You don't email files and you don't have to deal with crappy file formats - check it out!
Full disclosure : I co-founded and develop Locale.
This sounds like a one-off thing where I you do the translation once and then be done with it.
What we do in these cases (we usually work with a Translator for these kinds of things) is that we export all the keys in the YAML to Excel and send them that.
Once we get it back we usually task a intern with fixing up the yaml (after it's been translated back into YAML - we do this manually at the moment but a little script should be easy to implement)
Other solutions could be (if you do this a lot) that you include the translations into your app and enable through some JavaScript and maybe something similar to Aloha Editor the user to simply click on texts and translate them in the app. But that's a bit excessive and only makes sense if there are really a lot of translations to be done and you want to crowdsource them (Facebook did this back in the day)

ASP.NET MVC Response file should not download

I am generating a .cxml file on the server and pushing it to the browser based on certain queries. If I just link to a .cxml, it does what I expected and opens it in the respective application.
How can I generate a file and push it to the browser just like if it was linked to a file without it asking me to download it?
The link looks something like:
http://localhost/MyController/GetFile?q=TheQueryStringParam
Thanks.
Simply Response.Write(yourFileText) should do the trick

Posting files to Rails XML API

I have a Rails application setup to receive file attachments using Paperclip.
Now I need to allow a .net/C# cell phone application to post files along with the XML in the same way (or some other way if necessary: they could encode the image as base64 and send - they tried that initially - including the binary data in the tag that would normally be a file field in the web application, but it did not work.
I have found nothing in the way of documentation and wondering if anybody has experience or advice.
Surprising that there is apparently no documentation for doing this anywhere to be found. I ended up stumbling across a document on the Basecamp website describing how their file attachment process works for API users and used it as a guideline.
http://developer.37signals.com/basecamp/
with help from this article about posting files:
http://www.codevil.com/index.php/2009/05/23/posting-and-getting-files-in-rubyrails/
I modified my initial setup so that, rather than passing the tag in the XML, they first post a file and receive an file ID in response.
Then they post the XML with that reference and their .
Then I use before_validation and after_save callbacks to set the file with Paperclip, and remove the tmp file after the save.

Resources