Upload file using Angular JS - angularjs

I need to save a PDF file which the user uploads to database as a byte array (in Angular JS). I have tried using the file upload module provided by Angular. It doesnt seem to work for me.I have also tried posting the PDF file through a $http post call of jquery. This method works if I accept the data at the server side as a dynamic object of Newtonsoft. However I need a byte array and I am unable to convert this object to a byte array.

This questions is not really about angular but instead it is, based on your description, about how to upload a file using WebApi.
I would recommend your start trying to upload your file using this exmaple:
http://blogs.msdn.com/b/henrikn/archive/2012/03/01/file-upload-and-asp-net-web-api.aspx
When it is ready then adapting it to your angular app.

I had a similar issue a while back. Have a look at this Stack Overflow link.
Uploading/Downloading Byte Arrays with AngularJS and ASP.NET Web API
If you still have some questions, let me know.
I am sending and receiving a lot of byte array data between my clients and servers using Web API. The approach I use is compatible with iPhones, iPad, Android devices, Macs, and Windows PCs/laptops. I haven't checked it on Windows phones yet, but do not expect any problems.
Regards....

Related

How to fetch text file from google drive with json contents React Native

I need to access a simple text file from my google drive in React Native.
I saw in this post about how you can use this link structure to get a photo from google drive: https://drive.google.com/uc?export=view&id=YOUR PHOTO ID. Is there a structure like this to get a text document?
People keep telling me to setup a backend using sqlite or something but it seems so overkill for the very little that I need. I don't need to set data I just need to read it from a URL. Also, I tried doing a backend but from my limited knowledge, I can't use a backend server on iOS.
Any Ideas?

best practice to pass mock data to Angular & Ionic

I am working on an Ionic phone app using AngualrJs as the framework. Now I faced an issue. I don't want my app to send an HTTP request to my backend(which use Ruby on Rails) API to do a manual test.
So I'm wondering what's the best practice to pass a mock JSON data as a response when I want to call the API.
I'm not familiar with Angular and Ionic, I can find some tutorials on both sides but I don't know what's is the best practice if use them together.
You can either store the data in localStorage after the first hit and read the data from localStorage every-time whenever you need.
https://medium.com/#petehouston/awesome-local-storage-for-ionic-with-ngstorage-c11c0284d658
Or you can use
$httpBackend
https://docs.angularjs.org/api/ngMock/service/$httpBackend
by saving json files locally and injecting them back when the application tries to hit the network . One limitation here, you cannot update the json file later after the user have installed the application.
So, localStorage is preferred if you want to cache the data you have received from network.

Display a doc/docx with AngularJS and Mongoose

I store word doc/docx as binary data file in mongoDB (not GridFS) and I would like to display it in my AngularJS client.
I probably should use Google Docs Viewer but what I would like to know is how how should mongoose send the file and how AngularJS should use the object it received to display it.
There aren'y currently any projects out there that allow you to render doc/docx in a browser (that I know of).
Your best bet would be to convert the document to HTML or a PDF before you store it in MongoDB (Apache Tika https://tika.apache.org/ can help with this).
If you are using HTML you can then render that easily enough, if you went for PDF take a look at PDF.js - https://mozilla.github.io/pdf.js/

Angularjs and Pdfkit - example of saving pdf to downloads

Can any share an example of using Angularjs and Pdfkit to save a file to the client downloads? I've got it rendering in the same window as the app, but need it as a pdf file. I'm assuming this is all done client side rather than the server side with the Pdfkit node module.
This solution can help you https://www.npmjs.com/package/ng-pdfkit, it's a An Angular wrapper for PDFKit.

Upload files to Angular or Rails

I´m trying to integrate a Blueimp Jquery File Upload plugin in my application.
My application has an AngularJS front-end running in a Node.js server and a Rails API backend running in a WEBrick server.
I would like to clarify which is the best practices to store the files? In Angular (this case Node.js) server or the Rails one.
Thanks,
Roberto.
I'm working on an app that has the exact same layout as yours and I came to the same question.
Since I'm trying to separate the back-end and front-end completely and have all the work with the db and files done in the back-end, I found that it's better to save the files in Rails server. That also gives you an option to do background operations with files (using sidekiq, for example), without making users wait for completion in the front-end.
There are lots of tools for file upload from angularJS to the server (Rails), but I personally found angular-file-upload directive easiest to understand and implement. I recommend you check it out.
I hope it helps,
Ulugbek

Resources