Y
Y
Yura Storchak2019-12-24 03:22:40
Photo hosting
Yura Storchak, 2019-12-24 03:22:40

Where can I upload images in jpg, png, svg formats and get direct links and use them for my website?

What service can be used so that it alone can upload images in jpg, png, svg formats and receive direct links and use them for your site? and so that I can structure inside this service in my account, such as sign, for which sites there is one group of images, for which sites another group of images.
PS Please do not offer offers with your hosting, I have an account in beget, but I still want to use some separate service for images and getting links.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2019-12-24
@yrchi_k

https://imgbb.com/
https://cloudinary.com/solutions/image_management
AWS S3

Uploading Files
import boto3
from botocore.exceptions import ClientError


def upload_file(file_name, bucket, object_name=None):
    """Upload a file to an S3 bucket

    :param file_name: File to upload
    :param bucket: Bucket to upload to
    :param object_name: S3 object name. If not specified then file_name is used
    :return: True if file was uploaded, else False
    """

    # If S3 object_name was not specified, use file_name
    if object_name is None:
        object_name = file_name

    # Upload the file
    s3_client = boto3.client('s3')
    try:
        response = s3_client.upload_file(file_name, bucket, object_name)
    except ClientError as e:
        logging.error(e)
        return False
    return True

Presigned URLs
import logging
import boto3
from botocore.exceptions import ClientError


def create_presigned_url(bucket_name, object_name, expiration=3600):
    """Generate a presigned URL to share an S3 object

    :param bucket_name: string
    :param object_name: string
    :param expiration: Time in seconds for the presigned URL to remain valid
    :return: Presigned URL as string. If error, returns None.
    """

    # Generate a presigned URL for the S3 object
    s3_client = boto3.client('s3')
    try:
        response = s3_client.generate_presigned_url('get_object',
                                                    Params={'Bucket': bucket_name,
                                                            'Key': object_name},
                                                    ExpiresIn=expiration)
    except ClientError as e:
        logging.error(e)
        return None

    # The response contains the presigned URL
    return response

Similar questions

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question