コード例 #1
0
ファイル: gophoto.go プロジェクト: Sing-Li/dockergophoto
func sendTempfileToArchive(tmpfilename string, archivefilename string, authenticated swift.Connection) error {
	defer os.Remove(tmpfilename)

	// read file into byte array
	bytearray, err := ioutil.ReadFile(tmpfilename)

	if err != nil {
		log.Printf("Failed to read temp file to bytearray - %v", err)
		return err
	}

	targetFilename := strings.ToLower(archivefilename)

	if targetFilename == "image.jpg" {
		targetFilename = "image_" + strconv.Itoa(randgen.Intn(1000000)+1) + ".jpg"
	}
	err2 := authenticated.ObjectPutBytes(albumfolder, targetFilename, bytearray, "image-jpeg")
	if err2 != nil {
		log.Printf("Failed to send temp file to archive - %v", err2)
		return err2
	}

	return nil

}