unity直接上传资源到oss

时间:2021-12-11 05:41:28
【文件属性】:

文件名称:unity直接上传资源到oss

文件大小:204KB

文件格式:DLL

更新时间:2021-12-11 05:41:28

unity

using System; using System.Collections; using System.Collections.Generic; using System.IO; using UnityEngine; using Aliyun.OSS; using UnityEditor; using Aliyun.OSS.Common; public class AliyunOss { // 创建OssClient实例。 OssClient client; string endpoint = "https://oss-cn-shenzhen.aliyuncs.com"; string accessKeyId = "LTAIEs3jNeemGrVB"; string accessKeySecret = "LCBXE73BHFkxwfOHVS7FOe0GBTaZVM"; string bucketName = "zhandingbo"; string objectName = "modal"; //string localFilename = "Assets/StreamingAssets"; //string outPath = "Assets/StreamingAssets"; //Application.temporaryCachePath string localFilename = "C:/Users/11854/Desktop/modal.png"; string outPath = "Assets/StreamingAssets"; //Application.temporaryCachePath #region 单例 private static AliyunOss mSelf = null; public static AliyunOss Instance { get { if (mSelf == null) { mSelf = new AliyunOss(); } return mSelf; } } AliyunOss() { client = new OssClient(endpoint, accessKeyId, accessKeySecret); } #endregion public void OssAb(string path, string name) { try { // 上传文件。 Debug.Log(path + "-----------" + objectName + path + "/" + name); // client.PutObject(bucketName, objectName + path + "/" + name, localFilename + path + "/" + name); // client.PutObject(bucketName, objectName , localFilename); client.PutObject(bucketName, path, name); Debug.Log("Oss succeeded"); } catch (Exception e) { Console.WriteLine(e); throw; } } }


网友评论

  • 这个可以用,我用在untiy里边,不过好像异步上传用不了,unity里边只能用直接传输的,可能是和unity单线程有关系吧
  • 就是一个dll不是脚本