SharePoint 2010 file upload via REST api

You can use Copy Web Service method to upload document in SharePoint 2010 But it is not a method of REST API.

Below is the article from where you will get all the details.

Uploading Content Into SharePoint (Let me count the ways)

Below is the code WORKING in SharePoint 2013 to upload a file in the same domain by using the REST API and jQuery

'use strict';

jQuery(document).ready(function () {

    // Check for FileReader API (HTML5) support.
    if (!window.FileReader) {
        alert('This browser does not support the FileReader API.');
    }
});

// Upload the file.
// You can upload files up to 2 GB with the REST API.
function uploadFile() {

    // Define the folder path for this example.
    var serverRelativeUrlToFolder = '/shared documents';

    // Get test values from the file input and text input page controls.
    var fileInput = jQuery('#getFile');
    var newName = jQuery('#displayName').val();

    // Get the server URL.
    var serverUrl = _spPageContextInfo.webAbsoluteUrl;

    // Initiate method calls using jQuery promises.
    // Get the local file as an array buffer.
    var getFile = getFileBuffer();
    getFile.done(function (arrayBuffer) {

        // Add the file to the SharePoint folder.
        var addFile = addFileToFolder(arrayBuffer);
        addFile.done(function (file, status, xhr) {

            // Get the list item that corresponds to the uploaded file.
            var getItem = getListItem(file.d.ListItemAllFields.__deferred.uri);
            getItem.done(function (listItem, status, xhr) {

                // Change the display name and title of the list item.
                var changeItem = updateListItem(listItem.d.__metadata);
                changeItem.done(function (data, status, xhr) {
                    alert('file uploaded and updated');
                });
                changeItem.fail(onError);
            });
            getItem.fail(onError);
        });
        addFile.fail(onError);
    });
    getFile.fail(onError);

    // Get the local file as an array buffer.
    function getFileBuffer() {
        var deferred = jQuery.Deferred();
        var reader = new FileReader();
        reader.onloadend = function (e) {
            deferred.resolve(e.target.result);
        }
        reader.onerror = function (e) {
            deferred.reject(e.target.error);
        }
        reader.readAsArrayBuffer(fileInput(0).files(0));
        return deferred.promise();
    }

    // Add the file to the file collection in the Shared Documents folder.
    function addFileToFolder(arrayBuffer) {

        // Get the file name from the file input control on the page.
        var parts = fileInput(0).value.split('\');
        var fileName = parts(parts.length - 1);

        // Construct the endpoint.
        var fileCollectionEndpoint = String.format(
                "{0}/_api/web/getfolderbyserverrelativeurl('{1}')/files" +
                "/add(overwrite=true, url='{2}')",
                serverUrl, serverRelativeUrlToFolder, fileName);

        // Send the request and return the response.
        // This call returns the SharePoint file.
        return jQuery.ajax({
            url: fileCollectionEndpoint,
            type: "POST",
            data: arrayBuffer,
            processData: false,
            headers: {
                "accept": "application/json;odata=verbose",
                "X-RequestDigest": jQuery("#__REQUESTDIGEST").val(),
                "content-length": arrayBuffer.byteLength
            }
        });
    }

    // Get the list item that corresponds to the file by calling the file's ListItemAllFields property.
    function getListItem(fileListItemUri) {

        // Send the request and return the response.
        return jQuery.ajax({
            url: fileListItemUri,
            type: "GET",
            headers: { "accept": "application/json;odata=verbose" }
        });
    }

    // Change the display name and title of the list item.
    function updateListItem(itemMetadata) {

        // Define the list item changes. Use the FileLeafRef property to change the display name. 
        // For simplicity, also use the name as the title. 
        // The example gets the list item type from the item's metadata, but you can also get it from the
        // ListItemEntityTypeFullName property of the list.
        var body = String.format("{{'__metadata':{{'type':'{0}'}},'FileLeafRef':'{1}','Title':'{2}'}}",
            itemMetadata.type, newName, newName);

        // Send the request and return the promise.
        // This call does not return response content from the server.
        return jQuery.ajax({
            url: itemMetadata.uri,
            type: "POST",
            data: body,
            headers: {
                "X-RequestDigest": jQuery("#__REQUESTDIGEST").val(),
                "content-type": "application/json;odata=verbose",
                "content-length": body.length,
                "IF-MATCH": itemMetadata.etag,
                "X-HTTP-Method": "MERGE"
            }
        });
    }
}

// Display error messages. 
function onError(error) {
    alert(error.responseText);
}

Check this article for more details.

Upload a file by using the REST API and jQuery

upload image error "An Ajax http request terminated abnormally.." on Google Chrome [closed]

My website i use Drupal 7.69

I use Google Chrome Version 83.0.4103.61 (Official Build) (64-bit)

when upload image it’s show

https://ibb.co/wR0wVr0

And click “Remove”

https://ibb.co/M9rj222

But i use Safari not have error.

sharepoint online – Manage folder permissions so site members cannot rename folder but allow them to upload files under folder

Could you not create a new permission level called “Upload Only”, and give only the “Add Items” list permission? (This will automatically also select “View Items” in the item permissions and “View Pages” and “Open” in the Site Permissions.)

Then you could break permission inheritance on your “shared” folder, and change the permission level that site members have on that folder from Edit or Contribute or whatever it is to your new “Upload Only” permission level.

Upload directory from my NGINX server

I have nginx with RTMP module on my server.
I want to know: there is some way to upload a directory each time a new file is created to another server?

Example:
My server create HLS playlists in my /directory.

Can I upload this /directory (each time is updated with a new file) to https://my-cdn.com/name ?
I can’t setup a cronjob to do this, because it will be so slowly.

File upload blocked – error code 0x800700de “The file type being saved or retrieved has been blocked.”

A user has encountered a curious issue when trying to upload a 3MB Excel file. There are already other files greater than 3MB is size, so that’s not the issue.

The error code is as you see in the picture below, “Error 0x800700DE: The file type being saved or retrieved has been blocked”. I found this error code on the SCCM Error Code Bible on page 39.

Error 0x800700DE

  • I’d be surprised if we’d put in place some kind of file blocking setting.
  • This is an Excel file in .xlsx format, it is not a macro.
  • Other Excel files have been uploaded already.
  • Perhaps there is something else within the file that Sharepoint wants to block? There is one link to another file on a file server contained in the file (I see this in Data/Connections/Edit Links in the Excel ribbon menu).

File Permissions (in Excel itself)

Excel Permissions

The file does have password protected worksheets – can this be a reason for upload being blocked? If so, where can I access these settings (I’m SP Admin)?

SP User Permissions

  • The user has contribute permissions and has uploaded other files today.
  • I’m the SP Admin and I also can not upload the file.

Other Links / Research

Suggested invalid characters in file name: see link here

8 – Upload an image to filesystem, rename it and set it as Profile Picture for current user

I have the external link of an image where I am trying to:

  1. Upload the image to filesystem.
  2. Rename the image.
  3. Set the owner of the image to current user.
  4. Set the image as Profile Picture for current user.

So far I have:

$full_name = "John Smith";
$picture_url = "https://scontent.fbey14-1.fna.fbcdn.net/v/t31.0-8/14054356_124897527960923_50194821455451882_o.jpg?_nc_cat=106&_nc_sid=09cbfe&_nc_ohc=P4i5oscJf0IAX_KFCfR&_nc_ht=scontent.fbey14-1.fna&oh=c13b6b2d8712db359f3be5e1ec835340&oe=5EF2B1A4";

// Download the picture to local filesystem.
$profile_pic = system_retrieve_file($picture_url, "public://profile-pictures", TRUE, FILE_EXISTS_REPLACE);

// Get the Profile Pic ID.
$profile_pic_id = $profile_pic->id();

// Load the image.
$picture = DrupalfileEntityFile::load($profile_pic_id);

// Rename the image.
$picture->setFilename("$full_name.jpg");
// Set the owner of the profile picture file.
$picture->setOwner($current_user);

// Save the image.
$picture->save();

$current_user->set('user_picture', $profile_pic_id);
$current_user->save();

The image is indeed uploaded to filesystem under public://profile-pictures, also is successfully set as profile picture of the current user.

and the filename of the image at /user/*/edit edit page is set to: john-smith.jpg, however, the filename of the image at public://profile-pictures is 14054356_124897527960923_50194821455451882_o.jpg while I am expecting it to be john-smith.png !

How to rename the image at the filesystem ?

and does $picture->setOwner($current_user) will set the owner of the image to the current user ?

How to upload all files & sub directory in a directory to sharepoint

I’m writing an automation script to transfer files & subdirectory in a directory to SharePoint from ubuntu. And I’m able to transfer the files from in a directory but failed when uploading the subdirectories.

For reference my code

#importing required packages
import sys
import requests
from requests_ntlm import HttpNtlmAuth
from config import config
import os


#Reading the configuration variables
username=config('sp_user').split("@")(0)
password=config('sp_password')
sharepoint_url=config('sp_base_path')
sp_folder_url=config('folderUrl')
path=config('path')
domain=config('domain')
domain_username=domain+'\'+username


#Reading the files from Linux
files = next(os.walk(path))(2)


for i in range(0, len(files)):
    filename = files(i)
    requestUrl = sharepoint_url + '/_api/web/getfolderbyserverrelativeurl('' + sp_folder_url + '')/Files/add(url='' + filename + '',overwrite=true)'
    with open( filename, 'rb') as file_input:
        try:
             headers = {'Content-Type': 'application/json; odata=verbose', 'accept': 'application/json;odata=verbose'}
             r = requests.post(sharepoint_url + "/_api/contextinfo",auth=HttpNtlmAuth(domain_username,password), headers=headers)
             formDigestValue = r.json()('d')('GetContextWebInformation')('FormDigestValue')
             headers = {'Content-Type': 'application/json; odata=verbose', 'accept': 'application/json;odata=verbose', 'x-requestdigest' : formDigestValue}
             uploadResult = requests.post(requestUrl,auth=HttpNtlmAuth(domain_username,'password'), headers=headers, data=file_input.read())


        except Exception as err: 
            print("Some error occurred: " + str(err))

May I know what should I need to achieve that and please help me to bridge the gap between my requirement. Could you please try to produce my code. Thanks in advancesh

Word documents remain checked out after I upload them in SharePoint Library 2013

I have a SP library with 2 mandatory content type column. When users are uploading(dragging) the documents then some documents remains checked out and some gets automatically checked in. I can not change the properties of those column. Need a out of the box solution for this.

magento2 – Unable to upload Category Thumbnail and Category Hover thumnail image

I am uploading the Category thumbnail image and category hover thumbnail image, but after saving the configuration both image links seems broken.
screenshot after uploading

when i am clicking on the link, its not correct, it is like
enter image description here

i can see that the directory path is repeating itself, so , kindly help

Batch upload documents or one at a time

I am designing an application service for a mobile phone. The user must submit a bunch of photographs and documents “the application”.

The way I have designed it, documents are stored locally then uploaded all at once at the end.

But the existing service uploads as the user goes along, one at a time.

Pros and cons:

Has anyone got any evidence of what might work better? A big draw back of the existing API is user cannot preview files once uploaded.