當前位置: 首頁>>代碼示例>>Golang>>正文


Golang DeviceFarm.CreateUpload方法代碼示例

本文整理匯總了Golang中github.com/aws/aws-sdk-go/service/devicefarm.DeviceFarm.CreateUpload方法的典型用法代碼示例。如果您正苦於以下問題:Golang DeviceFarm.CreateUpload方法的具體用法?Golang DeviceFarm.CreateUpload怎麽用?Golang DeviceFarm.CreateUpload使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/aws/aws-sdk-go/service/devicefarm.DeviceFarm的用法示例。


在下文中一共展示了DeviceFarm.CreateUpload方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: internalCreateUpload

func internalCreateUpload(client *devicefarm.DeviceFarm, arn, appPath, appType string) (string, string) {
	params := &devicefarm.CreateUploadInput{
		Name:        aws.String(tools.GetFileName(appPath)),
		ProjectArn:  aws.String(arn),
		Type:        aws.String(appType),
		ContentType: aws.String("application/octet-stream"),
	}
	resp, err := client.CreateUpload(params)
	errors.Validate(err, "Failed to upload an app")
	log.Println("Upload ARN:", *resp.Upload.Arn)
	log.Println("Upload URL:", *resp.Upload.Url)
	return *resp.Upload.Arn, *resp.Upload.Url
}
開發者ID:artemnikitin,項目名稱:devicefarm-ci-tool,代碼行數:13,代碼來源:service.go

示例2: uploadCreate

/* Create an upload */
func uploadCreate(svc *devicefarm.DeviceFarm, uploadName string, uploadType string, projectArn string) {

	uploadReq := &devicefarm.CreateUploadInput{
		Name:       aws.String(uploadName),
		ProjectArn: aws.String(projectArn),
		Type:       aws.String(uploadType),
	}

	resp, err := svc.CreateUpload(uploadReq)

	failOnErr(err, "error creating upload")
	fmt.Println(awsutil.Prettify(resp))
}
開發者ID:ainoya,項目名稱:devicefarm-cli,代碼行數:14,代碼來源:devicefarm-cli.go

示例3: uploadPut

/* Upload a file */
func uploadPut(svc *devicefarm.DeviceFarm, uploadFilePath string, uploadType string, projectArn string, uploadName string) (upload *devicefarm.Upload, err error) {

	debug := true

	// Read File
	file, err := os.Open(uploadFilePath)

	if err != nil {
		return nil, err
		fmt.Println(err)
	}

	defer file.Close()

	// Get file size
	fileInfo, _ := file.Stat()
	var fileSize int64 = fileInfo.Size()

	// read file content to buffer
	buffer := make([]byte, fileSize)
	file.Read(buffer)
	fileBytes := bytes.NewReader(buffer) // convert to io.ReadSeeker type

	// Prepare upload
	if uploadName == "" {
		uploadName = path.Base(uploadFilePath)
	}

	uploadReq := &devicefarm.CreateUploadInput{
		Name:        aws.String(uploadName),
		ProjectArn:  aws.String(projectArn),
		Type:        aws.String(uploadType),
		ContentType: aws.String("application/octet-stream"),
	}

	uploadResp, err := svc.CreateUpload(uploadReq)

	if err != nil {
		log.Fatal(err)
		return nil, err
	}

	uploadInfo := uploadResp.Upload

	upload_url := *uploadInfo.Url

	if debug {
		fmt.Println("- Upload Response result:")
		fmt.Println(awsutil.Prettify(uploadResp))
		fmt.Println(upload_url)
	}

	req, err := http.NewRequest("PUT", upload_url, fileBytes)

	if err != nil {
		log.Fatal(err)
		return nil, err
	}

	// Remove Host and split to get [0] = path & [1] = querystring
	strippedUrl := strings.Split(strings.Replace(upload_url, "https://prod-us-west-2-uploads.s3-us-west-2.amazonaws.com/", "/", -1), "?")
	req.URL.Opaque = strippedUrl[0]
	req.URL.RawQuery = strippedUrl[1]

	req.Header.Set("Content-Type", "application/octet-stream")
	req.Header.Add("Content-Length", strconv.FormatInt(fileSize, 10))

	// Debug Request to AWS
	if debug {
		fmt.Println("- HTTP Upload Request")
		debugHTTP(httputil.DumpRequestOut(req, false))
	}

	client := &http.Client{}

	res, err := client.Do(req)

	if debug {
		fmt.Println("- HTTP Upload Response")
		dump, _ := httputil.DumpResponse(res, true)
		log.Printf("} -> %s\n", dump)
	}

	if err != nil {
		log.Fatal(err)
		return nil, err
	}

	defer res.Body.Close()

	status := ""
	for status != "SUCCEEDED" {
		fmt.Print(".")
		time.Sleep(4 * time.Second)
		uploadReq := &devicefarm.GetUploadInput{
			Arn: uploadInfo.Arn,
		}

		resp, err := svc.GetUpload(uploadReq)
//.........這裏部分代碼省略.........
開發者ID:ainoya,項目名稱:devicefarm-cli,代碼行數:101,代碼來源:devicefarm-cli.go

示例4: uploadPut

/* Upload a file */
func uploadPut(svc *devicefarm.DeviceFarm, uploadFilePath string, uploadType string, projectArn string, uploadName string) {

	// Read File
	file, err := os.Open(uploadFilePath)

	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	defer file.Close()

	// Get file size
	fileInfo, _ := file.Stat()
	var fileSize int64 = fileInfo.Size()

	// read file content to buffer
	buffer := make([]byte, fileSize)
	file.Read(buffer)
	fileBytes := bytes.NewReader(buffer) // convert to io.ReadSeeker type

	// Prepare upload
	if uploadName == "" {
		uploadName = path.Base(uploadFilePath)
	}

	uploadReq := &devicefarm.CreateUploadInput{
		Name:        aws.String(uploadName),
		ProjectARN:  aws.String(projectArn),
		Type:        aws.String(uploadType),
		ContentType: aws.String("application/octet-stream"),
	}

	resp, err := svc.CreateUpload(uploadReq)
	fmt.Println(awsutil.Prettify(resp))

	uploadInfo := resp.Upload

	upload_url := *uploadInfo.URL

	fmt.Println(upload_url)

	req, err := http.NewRequest("PUT", upload_url, fileBytes)

	if err != nil {
		log.Fatal(err)
	}

	// Remove Host and split to get [0] = path & [1] = querystring
	strippedUrl := strings.Split(strings.Replace(upload_url, "https://prod-us-west-2-uploads.s3-us-west-2.amazonaws.com/", "/", -1), "?")
	req.URL.Opaque = strippedUrl[0]
	req.URL.RawQuery = strippedUrl[1]

	req.Header.Set("Content-Type", "application/octet-stream")
	req.Header.Add("Content-Length", strconv.FormatInt(fileSize, 10))

	// Debug Request to AWS
	debug(httputil.DumpRequestOut(req, false))

	client := &http.Client{}

	res, err := client.Do(req)

	dump, _ := httputil.DumpResponse(res, true)
	log.Printf("} -> %s\n", dump)

	if err != nil {
		log.Fatal(err)
	}
	defer res.Body.Close()

}
開發者ID:dmreiland,項目名稱:devicefarm-cli,代碼行數:73,代碼來源:devicefarm-cli.go


注:本文中的github.com/aws/aws-sdk-go/service/devicefarm.DeviceFarm.CreateUpload方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。