Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

About download messageSender's file #107

Open
af913337456 opened this issue Oct 25, 2023 · 6 comments
Open

About download messageSender's file #107

af913337456 opened this issue Oct 25, 2023 · 6 comments

Comments

@af913337456
Copy link

I am looking for how to download the images in the picture message sent to me by the other party. As for the voice in the voice message. I looked at the function and it doesn't seem to be present. Currently, the "ReadFilePart" function can download its own files. But it seems that the sender cannot download it. Did I miss it? Can you give me some guidance, thank you.

@dezi

@andreymelkov
Copy link

I am looking for how to download the images in the picture message sent to me by the other party. As for the voice in the voice message. I looked at the function and it doesn't seem to be present. Currently, the "ReadFilePart" function can download its own files. But it seems that the sender cannot download it. Did I miss it? Can you give me some guidance, thank you.

@dezi

when you listen updates, you can get catch updateType "updateNewMessage", update new message has Message.Content. Message Content has a few types: messageText, messagePhoto and so on. MessagePhoto has Photo. This is your file

@af913337456
Copy link
Author

I am looking for how to download the images in the picture message sent to me by the other party. As for the voice in the voice message. I looked at the function and it doesn't seem to be present. Currently, the "ReadFilePart" function can download its own files. But it seems that the sender cannot download it. Did I miss it? Can you give me some guidance, thank you.
@dezi

when you listen updates, you can get catch updateType "updateNewMessage", update new message has Message.Content. Message Content has a few types: messageText, messagePhoto and so on. MessagePhoto has Photo. This is your file

they are the basis info, not the body bytes

@zelenin
Copy link
Owner

zelenin commented Oct 26, 2023

Have you tried tdlibClient.DownloadFile(...)?

@af913337456
Copy link
Author

af913337456 commented Oct 26, 2023

Have you tried tdlibClient.DownloadFile(...)?

yes, this return the *File which containes only basis info, no []byte of the file. @zelenin

@zelenin
Copy link
Owner

zelenin commented Oct 26, 2023

// Represents a file
type File struct {
	meta
	// Unique file identifier
	Id int32 `json:"id"`
	// File size, in bytes; 0 if unknown
	Size int64 `json:"size"`
	// Approximate file size in bytes in case the exact file size is unknown. Can be used to show download/upload progress
	ExpectedSize int64 `json:"expected_size"`
	// Information about the local copy of the file
	Local *LocalFile `json:"local"`
	// Information about the remote copy of the file
	Remote *RemoteFile `json:"remote"`
}
// Represents a local file
type LocalFile struct {
	meta
	// Local path to the locally available file part; may be empty
	Path string `json:"path"`
	// True, if it is possible to download or generate the file
	CanBeDownloaded bool `json:"can_be_downloaded"`
	// True, if the file can be deleted
	CanBeDeleted bool `json:"can_be_deleted"`
	// True, if the file is currently being downloaded (or a local copy is being generated by some other means)
	IsDownloadingActive bool `json:"is_downloading_active"`
	// True, if the local copy is fully available
	IsDownloadingCompleted bool `json:"is_downloading_completed"`
	// Download will be started from this offset. downloaded_prefix_size is calculated from this offset
	DownloadOffset int64 `json:"download_offset"`
	// If is_downloading_completed is false, then only some prefix of the file starting from download_offset is ready to be read. downloaded_prefix_size is the size of that prefix in bytes
	DownloadedPrefixSize int64 `json:"downloaded_prefix_size"`
	// Total downloaded file size, in bytes. Can be used only for calculating download progress. The actual file size may be bigger, and some parts of it may contain garbage
	DownloadedSize int64 `json:"downloaded_size"`
}

we have File.LocalFile.Path

@andreymelkov
Copy link

andreymelkov commented Nov 7, 2023

Have you tried tdlibClient.DownloadFile(...)?

yes, this return the *File which containes only basis info, no []byte of the file. @zelenin

look @af913337456

photoId := contentPhoto.Photo.Sizes[len(contentPhoto.Photo.Sizes)-1].Photo.Id
file, _ := tdlibClient.DownloadFile(&client.DownloadFileRequest{
        FileId:      photoId,
        Priority:    1,
        Offset:      0,
        Limit:       0,
        Synchronous: true,
        })

file.Local.Path - it's your path file. It's located here FilesDirectory: filepath.Join(".tdlib", "files"),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants