// NewVoiceUpload creates a new voice uploader.
//
// chatID is where to send it, file is a string path to the file,
// FileReader, or FileBytes.
548348
func NewVoiceUpload(chatID int64, file interface{}) VoiceConfig {
	return VoiceConfig{
		BaseFile: BaseFile{
			BaseChat:    BaseChat{ChatID: chatID},
			File:        file,
			UseExisting: false,
		},
	}
}
1206791
func NewUploadTaskFile(ctx *middleware.Context, handler UploadTaskFileHandler) *UploadTaskFile {
	return &UploadTaskFile{Context: ctx, Handler: handler}
}
727421
func (b *BigIP) UploadFile(f *os.File) (*Upload, error) {
	if strings.HasSuffix(f.Name(), ".iso") {
		err := fmt.Errorf("File must not have .iso extension")
		return nil, err
	}
	info, err := f.Stat()
	if err != nil {
		return nil, err
	}
	return b.Upload(f, info.Size(), uriShared, uriFileTransfer, uriUploads, info.Name())
}
1260793
func (c oauthClient) UploadFile(
	localFilePath string,
	remoteFileName string,
	contentType string,
	md5sum string,
) (wl.Upload, error) {
	fileContents, err := c.readLocalFile(localFilePath)
	if err != nil {
		return wl.Upload{}, err
	}

	initialUploadResp, err := c.createUpload(remoteFileName, contentType, len(fileContents), md5sum)
	uploadID := initialUploadResp.ID

	// Upload actual data using returned URL
	// Do not worry about multi-part upload for now
	err = c.uploadAPart(initialUploadResp.Part, fileContents)
	if err != nil {
		return wl.Upload{}, err
	}

	return c.finishUpload(uploadID)
}
704880
func (bot *BotAPI) uploadAndSend(method string, config Fileable) (Message, error) {
	params, err := config.params()
	if err != nil {
		return Message{}, err
	}

	file := config.getFile()

	resp, err := bot.UploadFile(method, params, config.name(), file)
	if err != nil {
		return Message{}, err
	}

	var message Message
	json.Unmarshal(resp.Result, &message)

	bot.debugLog(method, nil, message)

	return message, nil
}
150351
func (s *Session) onVoiceStateUpdate(st *VoiceStateUpdate) {

	// If we don't have a connection for the channel, don't bother
	if st.ChannelID == "" {
		return
	}

	// Check if we have a voice connection to update
	s.RLock()
	voice, exists := s.VoiceConnections[st.GuildID]
	s.RUnlock()
	if !exists {
		return
	}

	// We only care about events that are about us.
	if s.State.User.ID != st.UserID {
		return
	}

	// Store the SessionID for later use.
	voice.Lock()
	voice.UserID = st.UserID
	voice.sessionID = st.SessionID
	voice.ChannelID = st.ChannelID
	voice.Unlock()
}
982876
func NewUploadCommand(deps UploadDeps) modelcmd.ModelCommand {
	return modelcmd.Wrap(&UploadCommand{deps: deps})
}
424504
func NewStickerUpload(chatID int64, file interface{}) StickerConfig {
	return StickerConfig{
		BaseFile: BaseFile{
			BaseChat:    BaseChat{ChatID: chatID},
			File:        file,
			UseExisting: false,
		},
	}
}
901135
func (c *Client) UploadFile(ctx context.Context, file string, u *url.URL, param *Upload) error {
	if param == nil {
		p := DefaultUpload // Copy since we set ContentLength
		param = &p
	}

	s, err := os.Stat(file)
	if err != nil {
		return err
	}

	f, err := os.Open(filepath.Clean(file))
	if err != nil {
		return err
	}
	defer f.Close()

	param.ContentLength = s.Size()

	return c.Upload(ctx, f, u, param)
}
859706
func NewAnimationUpload(chatID int64, file interface{}) AnimationConfig {
	return AnimationConfig{
		BaseFile: BaseFile{
			BaseChat:    BaseChat{ChatID: chatID},
			File:        file,
			UseExisting: false,
		},
	}
}
1078190
func (c *Files) Upload(in *UploadInput) (out *UploadOutput, err error) {
	body, _, err := c.download("/files/upload", in, in.Reader)
	if err != nil {
		return
	}
	defer body.Close()

	err = json.NewDecoder(body).Decode(&out)
	return
}
1363177
func (bot TgBot) SimpleSendVoice(msg Message, audio string) (res Message, err error) {
	cid := msg.Chat.ID
	var payload interface{} = SendVoiceIDQuery{cid, audio, nil, nil, nil}
	if looksLikePath(audio) {
		payload = SendVoicePathQuery{cid, audio, nil, nil, nil}
	}
	ressm := bot.SendVoiceQuery(payload)
	return splitResultInMessageError(ressm)
}
407483
func (c *Communicator) Upload(path string, input io.Reader) error {
	wcp, err := c.newCopyClient()
	if err != nil {
		return err
	}
	log.Printf("[DEBUG] Uploading file to '%s'", path)
	return wcp.Write(path, input)
}
695502
func (request *Request) Upload(filename string, filetype string) (response *Response, err error) {
	postRequest, err := request.buildPost(uploadEndpoint, filename, filetype)
	if err != nil {
		return nil, err
	}
	return sendPost(postRequest)
}
432306
func (s *Service) uploadFile(fullPath string, data io.Reader, randomPublicId bool) (string, error) {
	// Do not upload empty files
	fi, err := os.Stat(fullPath)
	if err == nil && fi.Size() == 0 {
		return fullPath, nil
		if s.verbose {
			fmt.Println("Not uploading empty file: ", fullPath)
		}
	}
	// First check we have no match before sending an HTTP query
	changedLocally := false
	if s.dbSession != nil {
		publicId := cleanAssetName(fullPath, s.basePathDir, s.prependPath)
		ext := filepath.Ext(fullPath)
		match := &uploadResponse{}
		err := s.col.Find(bson.M{"$or": []bson.M{bson.M{"_id": publicId}, bson.M{"_id": publicId + ext}}}).One(&match)
		if err == nil {
			// Current file checksum
			chk, err := fileChecksum(fullPath)
			if err != nil {
				return fullPath, err
			}
			if chk == match.Checksum {
				if s.verbose {
					fmt.Printf("%s: no local changes\n", fullPath)
				} else {
					fmt.Printf(".")
				}
				return fullPath, nil
			} else {
				if s.verbose {
					fmt.Println("File has changed locally, needs upload")
				} else {
					fmt.Printf("U")
				}
				changedLocally = true
			}
		}
	}
	buf := new(bytes.Buffer)
	w := multipart.NewWriter(buf)

	// Write public ID
	var publicId string
	if !randomPublicId {
		publicId = cleanAssetName(fullPath, s.basePathDir, s.prependPath)
		pi, err := w.CreateFormField("public_id")
		if err != nil {
			return fullPath, err
		}
		pi.Write([]byte(publicId))
	}
	// Write API key
	ak, err := w.CreateFormField("api_key")
	if err != nil {
		return fullPath, err
	}
	ak.Write([]byte(s.apiKey))

	// Write timestamp
	timestamp := strconv.FormatInt(time.Now().Unix(), 10)
	ts, err := w.CreateFormField("timestamp")
	if err != nil {
		return fullPath, err
	}
	ts.Write([]byte(timestamp))

	// Write signature
	hash := sha1.New()
	part := fmt.Sprintf("timestamp=%s%s", timestamp, s.apiSecret)
	if !randomPublicId {
		part = fmt.Sprintf("public_id=%s&%s", publicId, part)
	}
	io.WriteString(hash, part)
	signature := fmt.Sprintf("%x", hash.Sum(nil))

	si, err := w.CreateFormField("signature")
	if err != nil {
		return fullPath, err
	}
	si.Write([]byte(signature))

	// Write file field
	fw, err := w.CreateFormFile("file", fullPath)
	if err != nil {
		return fullPath, err
	}
	if data != nil { // file descriptor given
		tmp, err := ioutil.ReadAll(data)
		if err != nil {
			return fullPath, err
		}
		fw.Write(tmp)
	} else { // no file descriptor, try opening the file
		fd, err := os.Open(fullPath)
		if err != nil {
			return fullPath, err
		}
		defer fd.Close()

		_, err = io.Copy(fw, fd)
		if err != nil {
			return fullPath, err
		}
		log.Printf("Uploading %s\n", fullPath)
	}
	// Don't forget to close the multipart writer to get a terminating boundary
	w.Close()
	if s.simulate {
		return fullPath, nil
	}

	upURI := s.uploadURI.String()

	if s.uploadResType == PdfType {
		upURI = strings.Replace(upURI, imageType, pdfType, 1)
	} else if s.uploadResType == VideoType {
		upURI = strings.Replace(upURI, imageType, videoType, 1)
	} else if s.uploadResType == RawType {
		upURI = strings.Replace(upURI, imageType, rawType, 1)
	}
	req, err := http.NewRequest("POST", upURI, buf)
	if err != nil {
		return fullPath, err
	}
	req.Header.Set("Content-Type", w.FormDataContentType())
	resp, err := http.DefaultClient.Do(req)

	if err != nil {
		return fullPath, err
	}
	defer resp.Body.Close()

	if resp.StatusCode == http.StatusOK {
		// Body is JSON data and looks like:
		// {"public_id":"Downloads/file","version":1369431906,"format":"png","resource_type":"image"}
		dec := json.NewDecoder(resp.Body)
		upInfo := new(uploadResponse)
		if err := dec.Decode(upInfo); err != nil {
			return fullPath, err
		}
		// Write info to db
		if s.dbSession != nil {
			// Compute file's checksum
			chk, err := fileChecksum(fullPath)
			if err != nil {
				return fullPath, err
			}
			upInfo.Id = upInfo.PublicId // Force document id
			upInfo.Checksum = chk
			if changedLocally {
				if err := s.col.Update(bson.M{"_id": upInfo.PublicId}, upInfo); err != nil {
					return fullPath, err
				}
			} else {
				if err := s.col.Insert(upInfo); err != nil {
					return fullPath, err
				}
			}
		}
		return upInfo.PublicId, nil
	} else {
		return fullPath, errors.New("Request error: " + resp.Status)
	}
}
797469
func (u *ConcurrentUploader) UploadFile(item *Item, ps *isolatedclient.PushState, done func()) {
	u.wg.Add(1)
	go u.upload(item.RelPath, fileSource(item.Path), ps, done)
}
682664
func (c *Client) Upload(path string, r io.Reader) error {
	_, err := c.Files.Upload(&dropbox.UploadInput{
		Mode:   dropbox.WriteModeOverwrite,
		Path:   path,
		Reader: r,
		Mute:   true,
	})

	return err
}