Create a document using only client-side code - sharepoint

Is it possible to create a document inside document library using just client-side javascript?
Just a simple text or xml file...
There are examples on how to create/delete a folder or delete a file, or update a document property. And you can do anything you want with list items.
But what if I need to create a document in a document or forms library with ECMAScript object model in SP2010, or calling web services via ajax in MOSS? Is it feasible?

Of course you can do it. You just need to have content of file as a Stream or byte[].
Use such code to create file in library.

ok, i found there are multiple ways to do it, though all of them are normally used in desktop apps, not in browser.
Here is the list:
RPC: Simple ajax POSTing to _vti_bin/_vti_aut/author.dll can do the job quickly if you don't need to set metadata or handle multiple content types
Copy Web Service: CopyIntoItems method of copy.asmx service accepts base64-encoded file body
HTTP PUT: You can simply PUT your file to the desired destination, though this method can by unsupported by some browsers

Related

how to get web api in nodejs (without lib)

I am making a module that converts html to json in node environment. I would like to know how to access web browser api from node. How can I access document object with nodejs only without libraries such as cheerio and jsdom?
(I used Google Translate, sorry)
Node.js does not have built-in support for rendering HTML documents.
It doesn't execute JavaScript that it extracts from <script> elements inside an HTML document.
It has no native document object.
If you want one you either need to build it yourself or use a third-party library.

Creating an HTML or PDF "file" in memory and streaming it in Node.js

I have a need to create a pdf or html document within a Node.js express API which then sends that document over HTTP to an API managing our CMS.
So functionally I would like to create the document and POST it as part of a multipart-form upload POST request to an external service.
I see how to do this if after I create the file, I then turn around and write it disk. After that point I can do a read stream of the file from that path to format the POST request with the file.
However I'm wondering how I can perform this action without writing the file to disk and then reading it into a read stream. It seems I should be able to accomplish this without that IO.
Anybody able to point me to a good example or library that does something along these lines?
You can extend Writable and/or Readable streams. By the first look this library do what you need, with the same way - extending built-in streams.

JavaScript REST-API file upload security/ACL

I have a HTML5 static site and use Parse as the back end through REST API.
So my application id and REST API key are completely open to the public.
My classes have ACL so it should be relatively OK. But I also upload files to https://api.parse.com/1/files/ using JavaScript through REST-API .
How can I allow that only logged in users can upload files? Unlike normal classes on which I can set class wide ACL, anyone can upload files to my parsing application.
First off I would ask why you are using the REST API instead of the native JavaScript API... the JavaScript API uses the REST API under the covers, it just adds a nicer layer of interaction to work with.
Anyway, that aside you can't stop people from uploading files unfortunately. You can stop them from assigning those files to records via ACLs though, and you can do a cleanup on files that are not linked to objects.

Serve custom javascript to browser via Node.js app

I developed a small node.js app in which I can configure conditions for a custom javascript file, which can be embedded in a webpage, and which modifies the DOM of that page in the browser on load. The configuration values are stored in MongoDB. (For sake of argument: add class "A" to DOM element with ID "B" )
I have difficulties to figure out the best way to serve requests / the JavaScript file.
Option 1 and my current implementation is:
I save a configuration in the node app and a distinct JavaScript
file is created for that configuration.
The page references that file which is hosted and served by the server.
Option 2 and where I think I want and should go is:
I saves a configuration (mongodb) NO JavaScript file is created Pages
a generic JavaScript link (for instance: api.service.com/javascript.js)
Node.js / Express app processes the request, and
returns a custom JavaScript (file?) with the correct values as saved in mongodb for that configuration
Now, while I believe this is the right way to go about it, I am unsure HOW to go about it. Any ideas and advise are very welcome!
Ps: For instance I wonder how best to authenticate or identify the origin, user and requested configuration. Shall I do this like: api.service.com/javascript.js&id="userID" - is that good practice?
Why not serve up a generic Javascript file which can take a customized json object (directly from mongodb) and apply the necessary actions? You can include the json data on the page if you really need to have everything embedded, but breaking up configuration and code is the most maintainable approach.

NSURLSession Downloading Many Files, How shall I update the metadata?

I am building an app that downloads files and it keeps some metadata related to the file in core data.
I was very intrigued by the NSURLSession download task as it will allow me to download in the background and not have to write my own queueing mechanism.
My problem is when I get the callback
- (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)location {
What pattern or method should I use to update the associated metadata for this file after moving it to the application sandbox? Specifically, I need to set a property on the metadata that will tell the application that the file is already downloaded.
I had originally started down the path of adding a property to the download task via associated objects that will tell me the objectid of the core data object. but it started to seem very hacky and it seems like there should be a simpler method.
Does anyone have an idea? am I explaining the problem sufficiently?
Your callback contains the original NSURL. Store the URL as part of your metadata. When the download completes, fetch the metadata record for that URL and update it.

Resources