예제 #1
0
        public static bool StoreFile(OssHelper oss, string bucketName, string oldFileUrl, string fileUrl, out string newFileUrl)
        {
            newFileUrl = "";
            // tmp -> origin
            string fileName = fileUrl.toFileName();

            if (fileName.Trim().Length != 0)
            {
                string fileNameTemp   = fileName.toTemp();
                string fileNameNormal = fileName.toNormal();
                newFileUrl = fileUrl.Replace(fileName, fileNameNormal);
                if (oss.ExistKey(bucketName, fileNameNormal))
                {
                    return(true);
                }
                if (!oss.ExistKey(bucketName, fileNameTemp))
                {
                    return(false);
                }
                try
                {
                    oss.CopyObject(bucketName, fileNameTemp, fileNameNormal);
                }
                catch
                {
                    return(false);
                }
            }

            // delete tmp
            fileName = oldFileUrl.toFileName();
            if (fileName != "")
            {
                try
                {
                    oss.DeleteObject(bucketName, fileName);
                }
                catch { }
            }
            return(true);
        }