Ejemplo n.º 1
0
func (command *commandUpload) Execute(resource *handler.Resource) {
	params := resource.Params.(*paramsUpload)
	containerName := params.container
	objectName := params.object
	opts := params.opts
	var readSeeker io.ReadSeeker
	var err error
	if stream := params.stream; stream {
		readSeeker = os.Stdin
	} else if fileName := params.fileName; fileName != "" {
		// this file will be closed by Gophercloud, if not closed before then
		readSeeker, err = os.Open(fileName)
		if err != nil {
			resource.Err = err
			return
		}
	} else {
		content := params.content
		readSeeker = strings.NewReader(content)
	}
	rawResponse := objects.Create(command.Ctx.ServiceClient, containerName, objectName, readSeeker, opts)
	if rawResponse.Err != nil {
		resource.Err = rawResponse.Err
		return
	}
	resource.Result = fmt.Sprintf("Successfully uploaded object [%s] to container [%s]\n", objectName, containerName)
}
Ejemplo n.º 2
0
func (command *commandUpload) Execute(resource *handler.Resource) {
	params := resource.Params.(*paramsUpload)
	containerName := params.container
	objectName := params.object
	stream := params.stream
	opts := params.opts

	rawResponse := objects.Create(command.Ctx.ServiceClient, containerName, objectName, stream, opts)
	if rawResponse.Err != nil {
		resource.Err = rawResponse.Err
		return
	}
	resource.Result = fmt.Sprintf("Successfully uploaded object [%s] to container [%s]\n", objectName, containerName)
}