">mixi Developer Center (mDC)

mixi Apps

mixi Apps (English) » Technical Specification » PC » Let's upload an image to the photo album

Let's upload an image to the photo album

Using the photo-uploading API from the mixi app, you can register the image file created or decorated by SAP to the user’s simply published photo album. For example, decorating in the mixi app and reregistering the result to the album, you can communicate with friends using the decorated picture. In addition, a chain reaction is initiated when the friends who see the picture add new decorations with the mixi app.

This document explains how to technologically use the photo-uploading API from the mixi app.

Preparing for Photo Uploading API

You need to previously prepare for using the Photo Uploading API.

The procedure for uploading

The procedure for registering the image file to a simply published photo album from a mixi app with the photo-uploading API is as shown below.

  1. Prepare the image file that you want to register on the SAP side web server.
  2. Call the photo-uploading API in the mixi app
  3. The request is sent to obtain the photo from the mixi server on the SAP side Web server.
  4. Verify the signature on the SAP side Web server.
  5. The SAP side Web server returns the image file to the mixi server.
  6. Watching the thumbnail of the image file on the mixi app, the user can choose whether to register or not.
  7. The image file is registered to the simply published photo album on the mixi server.
Preparing for the image file

The image file that you want to register needs to be prepared not on a Web browser that a mixi app runs but a SAP side Web server. The available image files are JPEG and PNG. Since the prepared image file can be obtained from a mixi server, you need to determine the image file URL here and send it to the mixi app.

Calling photo-uploading API

You can call the photo-uploading API on the mixi app that receives the image file URL. This API is the mixi.requestUploadMediaItem() function.

static void mixi.requestUploadMediaItem(mediaItem, optCallback);

The argument is as shown below.

Name Description
mediaItem opensocial.MediaItem object that has the image file URL to upload.
optCallback Callback function called after finishing execution.

An example of this call function is as shown below.

var mediaItem = opensocial.newMediaItem(
        opensocial.MediaItem.Type.IMAGE, "http://server.name/image.png");
mixi.requestUploadMediaItem(mediaItem, function(response) {
    if (response.hadError()) {
        var code = response.getErrorCode();
        var msg = response.getErrorMessage();
        // エラー時の処理
    } else {
        // 成功時の処理
Obtaining an image file from a mixi server.

After calling the mix.requestUploadMediaItem() function above, a mixi server can send the request to obtain the image file based on the specified URL. Based on the request, the SAP side Web server returns the previously prepared image file to the mixi server in response.

The request is given a signature from the mixi server. The public key listed at the end of this paragraph is used to verify the signature. Verifying the signature with this public key, the SAP side Web server needs to judge the validity if the request is sent from the mixi server.

Also, the request includes opensocial_owner_id and opensocial_app_id parameters, which is included with the signature of the base string. With the verification of validity that the request is sent from the mixi server, please verify the identity (if the image file can be given to the target user) at the same time by using the parameters.

Please refer to the following document on how to verify a signed request in detail.

[Validating Signed Requests]

Checking user registration and calling the callback function.

After obtaining an image file from a mixi server, a pop-up window is displayed to ask whether the simple published album can be published. In the pop-up window, the thumbnail image that the mixi server obtains is listed.

After the agreement or denial of user registration, the pop-up window is closed and the callback function is called that specifies the mixi.requestUploadMediaItem() function. Using the argument of the callback function, you can check whether the registration is successful. Please implement the proper execution while checking the result.

Error code

If the posting failed, obtain the error code and error message, calling the getErrorCode() function and the getErrorMessage() function against the argument of the callback function. Here is the list of error codes and meanings. Please implement the proper execution such as displaying the posting execution error for the user.

Error code Error message 説明
400 Failed to fetch URL Proper response (200) is not obtained in spite of the attempt to obtain the image file from the specified URL.
400 Not supported image format The obtained content’s mime-type is not JPEG or PNG.
400 Invalid params The argument is invalid. (such as the URL is not correct)
401 Insufficient scope User permission for mixi_apps2 scope is not obtained.
403 Quota full The capacity for uploading reaches the limit capacity.
403 Forbidden The Uploading API is forbidden for some reason.
403 User canceled The user canceled the execution.
413 Image too large The requested image file size is too large.
500 Internal Server Error The execution cannot be completed because of a mixi side server error.

Value of xoauth_signature_publickey parameter and public Key

The value of xoauth_signature_publickey parameter and public key to verify the validation of a signed request are as shown below.

Value of xoauth_signature_publickey parameter


Public key