paraworld.map.UploadFile

Description

上传文件。
每次上传操作最多只能上传不大于1M的文件,对于大于1M的文件,需要分成多次进行上传。
对于图像图片的上传(即需要生成缩略图的用户图像),总文件大小不能大于1M
若要将一个文件分成多次进行上传,则必须提供totalByte参数,并且值必须大于0,第一次上传成功后会返回一个filePath节点(若在第一次上传时提供了filePath参数,则此返回值即提供的filePath参数),在其后的每次上传中都必须提供此参数
若 fromByte == 0 && fromByte + 当前上传数据的二进制数组的长度 == totalByte,则会将此次上传操作视为非分批上传,即将一个文件一次性上传完成。

Parameters

Required Name Type DescriptionSorted ascending
optional totalByte long 上传文件的二进制数组的总大小,如果isPhoto==true,则totalByte不可大于1024*1024
required file string 文件数据二进制的base64编码
optional extension string 文件的后缀名,如(.jpg .txt 等,若未提供,则从参数filePath中获取,若extension和filepPath都没有值,则没有后缀名)
optional isPhoto boolean 是否是图片,如果是,则会生成一个原图(原图最大宽度若大于256,则会适度缩小)和一个小图,默认值为false
optional isHeadPic boolean 是否是用户图像,如果该值为true,则isPhoto必须为true,默认值为false
optional fromByte long 此次上传的数据在整个文件的二进制数组中的起始位置,当分多次上传一个文件时,若非第一次上传,则必须有fromByte、totalByte、filePath参数
required sessionKey string 用户凭证。上传文件时必须登录
optional overwrite int 若指定的目录中已存在同名的文件,是否覆盖它(即删除旧文件,保存新文件),0:否,1:是。如果为0,当指定目录中已存在同名的文件时,会返回错误码:410
optional format int 返回的数据格式(0:XML 1:JSON),默认值为0
optional filePath string 逻辑路径。若未指定,则会默认为 “upload/[当前日期]/[随机文件名][后缀名]”

Example Return XML

当将一个文件分成多次上传时,非最后一次返回:
<msg xmlns="">
        <fileSize type="string">200000</fileSize>
        <filePath type="string">upload/2008-8-25/34bf7b12-3b14-4510-ae71-8e5b9e92ecac.jpg</filePath>
</msg>
最后一次返回:
<msg xmlns="">
        <fileSize type="string">648704</fileSize>
        <fileURL type="string">http://api.pala5.com:81/Uploads/UserUpload/2008-8-25/e85cf3ca-eaf4-4bcd-b3a2-4ee02a12d4dc.jpg</fileURL>
        <fileCRC type="string">1665963060</fileSrc32>
        <filePath type="string">upload/2008-8-25/34bf7b12-3b14-4510-ae71-8e5b9e92ecac.jpg</filePath>
</msg>

若所传参数中isPhoto==true,即所传文件是一个用户图像,则会生成一个缩略图,返回值中会有此缩略图的URL:

        <fileURL_Small type="string">http://api.pala5.com:81/Uploads/UserUpload/Small/890c79da-4201-4da1-9c52-a77a1ca408cd.jpg</fileURL_Small>

Example Return JSON

{"fileURL":"http:\/\/localhost:1630\/Uploads\/UserUpload\/2008-12-8\/1e0a5342-83d7-4c12-9973-974b9d1f67c4.jpg",
"filePath":"\/cyf\/test2","fileSize":"96463","fileCrc32":"1106263707"}

Error Codes

当发生异常时,返回数据中会有一个“errorCode”节点,该节点记录了错误码。0:无异常 500:未知错误 499:提供的数据不完整 498:非法的访问 497:数据不存在或已被删除 496:未登录

查看完整的Error Code

Test Cases

case 1

Input:

{

        ["filePath"]="map/test.jpg",

        ["file"]="R0lGODlhBwAJAIABAAAzzP///yH5BAEAAAEALAAAAAAHAAkAAAIMjI+Am9yhoDRRVnoKADs=",

        ["extension"]=".jpg",

        ["sessionKey"]="fae5feb1-9d4f-4a78-843a-1710992d4e00",

}

Result:

{

        ["fileCRC"]="4279738660",

        ["fileURL"]="http://192.168.0.221:81/Uploads/UserUpload/2008-5-7/a373295b-aecc-47d4-bc59-50ba00289602.jpg",

}
Topic revision: r11 - 2009-01-04 - CaoYF
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback