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

download uploaded file #70

Open
khatarat opened this issue May 23, 2018 · 1 comment
Open

download uploaded file #70

khatarat opened this issue May 23, 2018 · 1 comment

Comments

@khatarat
Copy link

hi
i want to upload a file with telegram api Uploader and then download it. but for request a download task in downloader i need volume_id, secret and localId but i dont know how can i get this parameters.

uploader just give me a uniqId.

can you tell me how can i get this 3 parameters for uploaded file?
volume_id
secret
localId

@onixred
Copy link

onixred commented Jun 22, 2018

I take a message and convert it's structure

pay attention to the line class TLFileLocation

mediaEntity.setLocation(curentLocation);
	public static MessageEntity convertTLMessage2MessageEntity(TLMessage message) {
		MessageEntity messageEntity = new MessageEntity();
		messageEntity.setText(message.getMessage());
		messageEntity.setId(message.getId());
		TLAbsMessageMedia media = message.getMedia();
		if (media instanceof TLMessageMediaWebPage) {
			TLAbsWebPage absWebPage = ((TLMessageMediaWebPage) media).getWebPage();
			if (absWebPage instanceof TLWebPage) {
				MediaEntity mediaEntity = convertTLWebPage2MediaEntity((TLWebPage) absWebPage);
				messageEntity.setMedia(mediaEntity);
			}
		}
		return messageEntity;
	}

	public static MediaEntity convertTLWebPage2MediaEntity(TLWebPage media) {
		MediaEntity mediaEntity = new MediaEntity();
		mediaEntity.setTitle(media.getTitle());
		mediaEntity.setDescription(media.getDescription());
		mediaEntity.setUrlName(media.getDisplay_url());
		mediaEntity.setUrl(media.getUrl());

		TLAbsPhoto tLAbsPhoto = media.getPhoto();
		if (tLAbsPhoto instanceof TLPhoto) {
			// Java timestamp is millisecods past epoch
			Instant instant = Instant.ofEpochSecond(((TLPhoto)tLAbsPhoto).getDate());
			ZonedDateTime zdt = ZonedDateTime.ofInstant(instant, ZoneId.systemDefault());
			Calendar cal =  GregorianCalendar.from(zdt);
			mediaEntity .setDate(cal.getTime());
			TLVector<TLAbsPhotoSize> sizes = ((TLPhoto) tLAbsPhoto).getSizes();
			if (sizes != null && !sizes.isEmpty()) {
				int maxSize = 0;
				TLFileLocation curentLocation = null;
				for (TLAbsPhotoSize tLAbsPhotoSize : sizes) {
					if (tLAbsPhotoSize instanceof TLPhotoSize) {
						if (((TLPhotoSize) tLAbsPhotoSize).getSize() > maxSize) {
							TLAbsFileLocation tLAbsFileLocation = ((TLPhotoSize) tLAbsPhotoSize).getLocation();
							if (tLAbsFileLocation instanceof TLFileLocation) {
								maxSize = ((TLPhotoSize) tLAbsPhotoSize).getSize();
								curentLocation = ((TLFileLocation) tLAbsFileLocation);
							}
						}
					}
				}
				mediaEntity.setLocation(curentLocation);
				mediaEntity.setSize(maxSize);
			}
		}
		return mediaEntity;
	}
}

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

2 participants