简体   繁体   English

Amazon Storage ec2 像 S3 一样直接访问

[英]Amazon Storage ec2 direct access like S3

I am new to Amazon, got confused about Amazon ec2, Got few queries I am unable to find on google Q: Is possible we can directly store images ( by SDK provided by amazon like S3 not by consuming rest api's ) Q: Is ec2 purely for backened services only我是亚马逊新手,对亚马逊 ec2 感到困惑,有几个查询我无法在谷歌上找到 Q:我们是否可以直接存储图像(由亚马逊提供的 SDK,如 S3,而不是通过使用 rest api's) Q:纯粹是 ec2仅适用于支持的服务

I have checked the android aws, they have sdk for ec2, but I am unable to figure it out, how to use to directly access ec2 instance and do some storage stuff.我检查了 android aws,他们有 ec2 的 sdk,但我无法弄清楚如何使用直接访问 ec2 实例并做一些存储工作。

SDK Link SDK 链接

https://github.com/aws-amplify/aws-sdk-android https://github.com/aws-amplify/aws-sdk-android

The reason I am not using s3 is, S3 storage is not available in Africa Region, kind of must requirement, suggestions will be appreciated. 我不使用 s3 的原因是,非洲地区没有 S3 存储,这是必须的要求,我们将不胜感激。

The s3 is available to Africa regions, Check below the comment, I have included the link which enlists all the supported regions s3 适用于非洲地区,请查看评论下方,我已包含列出所有受支持地区的链接

S3 is NOT a server and is just an Object store . S3 不是服务器,只是Object store Sort of like a hardware where you can store 1 file at a time.有点像硬件,一次可以存储一个文件。 You can use S3 to save any type of files (non extendable ones).您可以使用 S3 保存任何类型的文件(不可扩展的文件)。 EC2 is just a server / machine which can be used for anything you like it be. EC2 只是一个服务器/机器,可以用于任何你喜欢的事情。

If you just want to save files on S3 using Android SDK then you can do so.如果您只想使用 Android SDK 在 S3 上保存文件,那么您可以这样做。 Check the DownloadTask and Transfer* classes to download / upload files on S3 from Android.检查DownloadTaskTransfer*类以从 Android 下载/上传 S3 上的文件。 Reference to S3 classes in Android SDK is below参考 Android SDK 中的 S3 类如下

https://github.com/aws-amplify/aws-sdk-android/tree/main/aws-android-sdk-s3/src/main/java/com/amazonaws/mobileconnectors/s3/transferutility https://github.com/aws-amplify/aws-sdk-android/tree/main/aws-android-sdk-s3/src/main/java/com/amazonaws/mobileconnectors/s3/transferutility

Thanks for help, at last I found the documentation which supports all regions for amazon s3 which is https://docs.aws.amazon.com/general/latest/gr/s3.html感谢您的帮助,最后我找到了支持亚马逊 s3 所有区域的文档,即https://docs.aws.amazon.com/general/latest/gr/s3.html

Rest is simple Rest 简单

        val amazonS3Client = getAmazonS3Client()
        var uploadObserver = TransferUtility.builder()
            .defaultBucket("enter_your_s3_bucket_name")
            .context(ApplicationCOntext)
            .s3Client(amazonS3Client).build()

        uploadObserver.upload("enter_your_s3_bucket_name",
            "" + "fileName" + ".mp4",
            File(""),
            CannedAccessControlList.PublicRead).setTransferListener(object : TransferListener {
            override fun onStateChanged(id: Int, state: TransferState?) {
                if (state == TransferState.COMPLETED) {
                    success.invoke()
                }

            }

            override fun onProgressChanged(id: Int, bytesCurrent: Long, bytesTotal: Long) {
            }

            override fun onError(id: Int, ex: Exception?) {
                exception?.invoke(ex!!)
            }
        })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM