Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Add a file to a sub site using REST API

$
0
0

Hi,

I'm trying to add a file from a Rootsite to a SubSite using REST API.

There some code:

$.ajax ( {
	url : _spPageContextInfo.siteAbsoluteUrl + "/_api/web/getFileByServerRelativeUrl('" + selected + "')/$value",
			type : "GET",
			headers : { "Accept" : "application/json;odata=verbose" },
			binaryStringResponseBody : true
		} )
		.done ( function ( data ) {
			if ( data === null ) {
				console.error ( "The file wasn't downloaded" );
				return;
			}

			$.ajax ( {
					url : "https://dev.sharepoint.com/sites/myrootsite/_api/web/getFolderByServerRelativeUrl('/sites/myrootsite/mysubsite/Lists/uploadeddocs')/Files/add(url='testFileUploaded.docx')",
					type : "POST",
					data : sdata,
					headers : {"Accept" : "application/json;odata=verbose","X-RequestDigest" : $ ( "#__REQUESTDIGEST" ).val ( )
					}
				} )
				.done ( function ( ) { console.log ( "fuck yeah" ); } )
				.fail ( function ( ) { console.error ( "as usual" ); } );

		} );

but I always get the "File not found" error.

If I using the same code to create the file in the current rootsite it works.

Some ideas?

Cheers


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>