B2G/gecko/services/common/bagheeraclient.js
/**
   * Upload a JSON payload to the server.
   *
   * The return value is a Promise which will be resolved with a
   * BagheeraClientRequestResult when the request has finished.
   *
   * @param namespace
   *        (string) The namespace to post this data to.
   * @param id
   *        (string) The ID of the document being uploaded. This is typically
   *        a UUID in hex form.
   * @param payload
   *        (string|object) Data to upload. Can be specified as a string (which
   *        is assumed to be JSON) or an object. If an object, it will be fed into
   *        JSON.stringify() for serialization.
   * @param deleteOldID
   *        (string) Old document ID to delete as part of upload. If not
   *        specified, no old documents will be deleted as part of upload. The
   *        string value is typically a UUID in hex form.
   *
   * @return Promise<BagheeraClientRequestResult>
   */
Upload a JSON payload to the server.
The return value is a Promise which will be resolved with a
BagheeraClientRequestResult when the request has finished.

@param namespace
(string) The namespace to post this data to.
@param id
(string) The ID of the document being uploaded. This is typically
a UUID in hex form.
@param payload
(string|object) Data to upload. Can be specified as a string (which
is assumed to be JSON) or an object. If an object, it will be fed into
JSON.stringify() for serialization.
@param deleteOldID
(string) Old document ID to delete as part of upload. If not
specified, no old documents will be deleted as part of upload. The
string value is typically a UUID in hex form.

@return Promise
Upload a JSON payload to the server . The return value is a Promise which will be resolved with a BagheeraClientRequestResult when the request has finished . @param namespace ( string ) The namespace to post this data to . @param id ( string ) The ID of the document being uploaded . This is typically a UUID in hex form . @param payload ( string|object ) Data to upload . Can be specified as a string ( which is assumed to be JSON ) or an object . If an object it will be fed into JSON . stringify () for serialization . @param deleteOldID ( string ) Old document ID to delete as part of upload . If not specified no old documents will be deleted as part of upload . The string value is typically a UUID in hex form . @return Promise
function uploadJSON(namespace, id, payload, deleteOldID=null) {
    if (!namespace) {
      throw new Error("namespace argument must be defined.");
    }
    if (!id) {
      throw new Error("id argument must be defined.");
    }
    if (!payload) {
      throw new Error("payload argument must be defined.");
    }
    let uri = this._submitURI(namespace, id);
    let data = payload;
    if (typeof(payload) == "object") {
      data = JSON.stringify(payload);
    }
    if (typeof(data) != "string") {
      throw new Error("Unknown type for payload: " + typeof(data));
    }
    this._log.info("Uploading data to " + uri);
    let request = new RESTRequest(uri);
    request.loadFlags = this._loadFlags;
    request.timeout = this.DEFAULT_TIMEOUT_MSEC;
    if (deleteOldID) {
      request.setHeader("X-Obsolete-Document", deleteOldID);
    }
    let deferred = Promise.defer();
    data = CommonUtils.convertString(data, "uncompressed", "deflate");
    request.setHeader("Content-Type", "application/json+zlib; charset=utf-8");
    this._log.info("Request body length: " + data.length);
    let result = new BagheeraClientRequestResult();
    result.namespace = namespace;
    result.id = id;
    request.onComplete = this._onComplete.bind(this, request, deferred, result);
    request.post(data);
    return deferred.promise;
  }
function uploadJSON ( namespace , id , payload , deleteOldID = null ) { if ( ! namespace ) { throw new Error ( "namespace argument must be defined." ) ; } if ( ! id ) { throw new Error ( "id argument must be defined." ) ; } if ( ! payload ) { throw new Error ( "payload argument must be defined." ) ; } let uri = this . _submitURI ( namespace , id ) ; let data = payload ; if ( typeof ( payload ) == "object" ) { data = JSON . stringify ( payload ) ; } if ( typeof ( data ) != "string" ) { throw new Error ( "Unknown type for payload: " + typeof ( data ) ) ; } this . _log . info ( "Uploading data to " + uri ) ; let request = new RESTRequest ( uri ) ; request . loadFlags = this . _loadFlags ; request . timeout = this . DEFAULT_TIMEOUT_MSEC ; if ( deleteOldID ) { request . setHeader ( "X-Obsolete-Document" , deleteOldID ) ; } let deferred = Promise . defer ( ) ; data = CommonUtils . convertString ( data , "uncompressed" , "deflate" ) ; request . setHeader ( "Content-Type" , "application/json+zlib; charset=utf-8" ) ; this . _log . info ( "Request body length: " + data . length ) ; let result = new BagheeraClientRequestResult ( ) ; result . namespace = namespace ; result . id = id ; request . onComplete = this . _onComplete . bind ( this , request , deferred , result ) ; request . post ( data ) ; return deferred . promise ; }
Upload a JSON payload to the server.
Upload a JSON payload to the server .
// TODO proper header per bug 807134.